Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

阿菜痛苦得要死,哪位大牛救救我,一直wa

Posted by 08huozhixin at 2008-08-04 18:15:08 on Problem 1877
#include <iostream>
#include <iomanip> 
#include <cstdlib> 
using namespace std;
int A[901];
void Shift(int i,int n)//大根堆
{
	int tmp=A[i];
	int j=2*i+1;
	while(j<n)
	{
		if(j<n-1&&A[j]<A[j+1])
			j++;
		if(A[j]>tmp)
		{
			A[i]=A[j]; //将A[j](子结点)调到双亲位置上
			i=j; //修改i,j的值,以便向下"筛"
			j=2*i+1;
		}
		else break;
	}
	A[i]=tmp;
}
void Hsort(int n)
{
	int i;
	for(i=n/2;i>=0;i--)//建立初始堆
		Shift(i,n);
	for(i=0;i<n-1;i++)
	{
		int tmp=A[0];//交换
		A[0]=A[n-1-i];
		A[n-1-i]=tmp;
		Shift(0,n-1-i);//重新生成堆
	}
}
float Float(int c,int p)
{
	float q=0;
	int s=0;
	int i;
	for(i=0;i<p;i++)
	{
		s++;
		c-=(A[i+1]-A[i])*100*s;
		if(c>=0)
			q++;
		else
			break;
	}
	if((A[i+1]-A[i])*100*s>0)
	{
		q++;
	}
	c+=(A[i+1]-A[i])*100*s;
    cout.setf(ios::showpoint);
    cout.fill('0');
    cout<<"Water level is "<<setprecision(4)<<(A[i]*1000+(c*10)/s)/1000.0<<" meters.\n";
    cout<<(q*100)/p<<" percent of the region is under water.\n";
	return q;
}
int main()
{
	int m,n,i,c,cas=1;
	cin>>m>>n;
	while(m!=0)
	{
		int N=m*n;
	    for(i=0;i<N;i++)
		{
		    cin>>A[i];
		}
	    Hsort(N);
	    cin>>c;	
	    cout<<"Region "<<cas++<<endl;
	    Float(c,N);               
        cin>>m>>n;
	}	
	return 1;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator