标签:
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.
有一个n×m的网格,每个格子是边长10米的正方形,网格四周是无限大的墙壁。
输入每个格子的海拔高度,以及网格内雨水的总体积。
输出水位的海拔高度以及有多少百分比的区域有水(即高度严格小于水平面)。
1 #include <iostream> 2 #include <algorithm> 3 #include<iomanip> 4 int main() 5 { 6 using namespace std; 7 int n, m; 8 int hai[30 * 30]; 9 cin >> n >> m; 10 for (int i = 0; i < m*n; i++) 11 cin >> hai[i]; 12 sort(hai, hai + m*n); //排序,将输入的海拔高度从小到大排列 13 int T; 14 int k; 15 int h; 16 cin >> T; 17 for (int i = 0; i < n*m; i++) 18 { 19 T = T + 100*hai[i]; //将洪水总体积与 单个格子内海拔总体积 相加。 20 21 k = T / (100.0 * (i + 1)); //T 除以 (块数×面积)得到 平均海拔 22 23 if (k <= hai[i + 1]) //加等号!!!! 24 { //k<下一块格子的海拔,说明洪水只能淹没到这块格子 25 h = i; 26 27 break; 28 } 29 } 30 cout << "水位海拔:" << k << endl; 31 32 cout << fixed << setprecision(2) << (((h+1)*1.0) / (n*m))*100 << "%的区域里有水" << endl; 33 system("pause"); 34 return 0; 35 36 37 }
#include<iomanip.h>
cout<<setiosflags(ios::fixed)<<setprecision(n);
n即为小数点位数
标签:
原文地址:http://www.cnblogs.com/ghost-song/p/4462728.html