码迷,mamicode.com
首页 > 其他好文 > 详细

UVA - 815 Flooded!(模拟)

时间:2015-04-11 08:58:19      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

 Status

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.

Input 

The input consists of a sequence of region descriptions. Each begins with a pair of integers, m and n, each less than 30, giving the dimensions of the rectangular region in 10-meter units. Immediately following are m lines of n integers giving the elevations of the squares in row-major order. Elevations are given in meters, with positive and negative numbers representing elevations above and below sea level, respectively. The final value in each region description is an integer that indicates the number of cubic meters of water that will collect in the region. A pair of zeroes follows the description of the last region.

Output 

For each region, display the region number (1, 2, ...), the water level (in meters above or below sea level) and the percentage of the region‘s area under water, each on a separate line. The water level and percentage of the region‘s area under water are to be displayed accurate to two fractional digits. Follow the output for each region with a blank line.

Sample Input 

3 3
25 37 45
51 12 34
94 83 27
10000
0 0

Sample Output 

Region 1
Water level is 46.67 meters.
66.67 percent of the region is under water.



Miguel Revilla 2002-06-25

题目保证水会从海拔最低的格子开始填(出题人考虑的真全面)。虽说是求水在矩阵中的海拔,但把矩阵拆成一条链,把柱子从低到高排列,再从最低的格子注水,最后的海拔高度也是不会变的。每次淹没一个格子就把其体积也算到水的体积中,算下这时的水面高度,如果还有低于【或等于】水面高度的就加进来。

#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;		
	}
}




UVA - 815 Flooded!(模拟)

标签:

原文地址:http://blog.csdn.net/qq_18738333/article/details/44988517

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!