uva 815 Flooded!
题意:n*m的网格,每个网格10m的正方形,网格四周是无限大的墙壁,输入每个格子的高度和洪水的体积,求水位的高度和淹没的面积。
分析:水肯定是先淹没高度低的,后淹没高度高的,所以对所有海拔排序,从低向高遍历,直到遇到不能淹没的网格停止。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 using namespace std; 5 const int mmax=35*35; 6 int dp[mmax],n,m; 7 8 int main() 9 { 10 for (int kase = 1; scanf("%d%d", &n, &m), n&&m; kase++) 11 { 12 n*=m; 13 for(int i=0;i<n;i++) 14 cin>>dp[i]; 15 sort(dp,dp+n); 16 dp[n]=0x7fffffff; 17 18 int t;double sum; 19 cin>>sum;sum/=100; 20 21 for(t=1;t<=n;t++) 22 { 23 sum+=dp[t-1]; 24 if(sum/t<=dp[t]) 25 break; 26 } 27 printf("Region %d\n", kase); 28 printf("Water level is %.2lf meters.\n", sum/t); 29 printf("%.2lf percent of the region is under water.\n\n", t*100.0/n); 30 } 31 return 0; 32 }