UVa815

//UVa815 - Flooded!
//直接模拟,注意考虑临界情况
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
	//freopen("UVa815.in","r",stdin);
	int n, m, kase = 1;
	while(scanf("%d%d",&n,&m)==2 &&n &&m){
		int ans[30*30], i;	ans[0] = 1;
		for(i = 1; i<=n*m; i++) scanf("%d",&ans[i]);
		double h, h2 = 0.0; scanf("%lf",&h); h/=100.0;	//h为原来的水位,h2为每次用掉的水
		sort(ans+1,ans+n*m+1);
		for(i = 1; i < n*m; i++){
			h2 = i*(ans[i+1]-ans[i]);
			if(h>=h2)h -= h2;			//本次填水后是否仍有剩余
			else {ans[0] = 0; break;}	//ans[0]用作开关
		}
        printf("Region %d
",kase++);
        printf("Water level is %.2lf meters.
",ans[0]? (ans[n*m]+h/n/m): (ans[i]+h/i));
        printf("%.2lf percent of the region is under water.

",ans[0]? (100): (i*1.0/n/m)*100);  
	}
	return 0;
}

/*测试数据(考虑填满):已AC
3 3
25 37 45
51 12 34
94 83 27
100000
3 1
-6
-5
-4
301
0 0
*/

原文地址:https://www.cnblogs.com/gwj1314/p/9444925.html