UVa 815 洪水!
https://vjudge.net/problem/UVA-815
题意:一个n*m的方格区域,共有n*m个方格,每个方格是边长为10米的正方形,整个区域的外围是无限高的高墙,给出这n*m个方格的初始高度,和洪水的总体积,计算灌入洪水后这个方格区域的水面高度,以及洪水淹没比例。
思路:
看这张图就很容易明白。
1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 5 int ans[1000]; 6 7 int main() 8 { 9 //freopen("D:\\txt.txt", "r", stdin); 10 int m, n, kase = 0; 11 double flood, percent; 12 while (cin >> m >> n,m&&n) 13 { 14 percent = 1; 15 for (int i = 0; i < m*n; i++) 16 cin >> ans[i]; 17 cin >> flood; 18 flood /= 100.0; 19 sort(ans, ans + m*n); 20 double high; 21 for (int i = 1; i <= m*n; i++) 22 { 23 flood += ans[i - 1]; 24 high = flood / i; 25 if (high <= ans[i]) 26 { 27 percent = (double)i / (m*n); 28 break; 29 } 30 } 31 32 cout << "Region " << ++kase << endl; 33 printf("Water level is %.2lf meters.\n", high); 34 printf("%.2lf percent of the region is under water.\n\n", percent * 100); 35 } 36 return 0; 37 }