标签:
Time Limit: 3000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
Description
To enable homebuyers to estimate the cost of flood insurance, a real-estate firm provides clients with the elevation of each 10-meter by 10-meter square of land in regions where homes may be purchased. Water from rain, melting snow, and burst water mains will collect first in those squares with the lowest elevations, since water from squares of higher elevation will run downhill. For simplicity, we also assume that storm sewers enable water from high-elevation squares in valleys (completely enclosed by still higher elevation squares) to drain to lower elevation squares, and that water will not be absorbed by the land.
From weather data archives, we know the typical volume of water that collects in a region. As prospective homebuyers, we wish to know the elevation of the water after it has collected in low-lying squares, and also the percentage of the region‘s area that is
completely submerged (that is, the percentage of 10-meter squares whose elevation is strictly less than the water level). You are to write the program that provides these results.
3 3 25 37 45 51 12 34 94 83 27 10000 0 0
Region 1 Water level is 46.67 meters. 66.67 percent of the region is under water.
题目保证水会从海拔最低的格子开始填(出题人考虑的真全面)。虽说是求水在矩阵中的海拔,但把矩阵拆成一条链,把柱子从低到高排列,再从最低的格子注水,最后的海拔高度也是不会变的。每次淹没一个格子就把其体积也算到水的体积中,算下这时的水面高度,如果还有低于【或等于】水面高度的就加进来。
#include<iostream> #include<algorithm> #include<iomanip> using namespace std; int h[1000]; int main() { int n, m; int cas = 0; while (cin>>n>>m&&n) { for (int i = 0; i < n*m; i++) cin >> h[i]; sort(h, h + m*n); double V; double H; int k = 0; cin >> V; h[n*m] = 10e6; for (int i = 1; i <= n*m; i++) { V = V + 100.0*h[i - 1]; H = V / (100.0*i); if (H < h[i]) { k = i; break; } } cout << "Region " << ++cas << endl; cout << "Water level is "<<fixed<<setprecision(2)<< H <<" meters." << endl; cout<<fixed<<setprecision(2)<<(k*1.0)/(n*m)*100.0<<" percent of the region is under water." << endl<<endl; } }
标签:
原文地址:http://blog.csdn.net/qq_18738333/article/details/44988517