当前位置 : 主页 > 编程语言 > c语言 >

算法竞赛入门经典 第4章 4-10 flooded (sort)

来源:互联网 收集:自由互联 发布时间:2023-09-07
#includecstdio#includeiostream#includestring#includealgorithm#includecstringusing namespace std;int a[1000000];int main(){int m,n;int count=0;while(scanf("%d %d",m,n)==2mn){memset(a,0,sizeof(a));int i;count++;for(i=1;i=m*n;i++)cina[i];a[m*n
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;
int a[1000000];
int main(){
	int m,n;
	int count=0;
	while(scanf("%d %d",&m,&n)==2&&m&&n){
	memset(a,0,sizeof(a));
	int i;
	count++;
	for(i=1;i<=m*n;i++)cin>>a[i];
	a[m*n+1]=2111111110;
	double v;
	cin>>v;
	v=v/100.0;//防止溢出 
	sort(a+1,a+m*n+1);
	double sum=0,h,percenT;
	for(i=1;i<=m*n;i++){
		sum=sum+(double)(a[i+1]-a[i])*i;
		if(sum>=v){
			h=(double)a[i+1]-(double)(sum-v)/i;
			break;
		}
	}
	percenT=(double)i*100.0/(n*m);
	cout<<"Region "<<count<<endl;
	printf("Water level is %.2lf meters.\n",h);
	printf("%.2lf percent of the region is under water.\n",percenT);
	printf("\n");
  }
} 

上一篇:C. Hexadecimal's Numbers
下一篇:没有了
网友评论