uva 815
来源:互联网 发布:淘宝被处罚了怎么办 编辑:程序博客网 时间:2024/06/12 18:34
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 325 37 4551 12 3494 83 27100000 0
Sample Output
Region 1Water level is 46.67 meters.66.67 percent of the region is under water.
Miguel Revilla 2002-06-25
这道题其实挺简单的,因为数据量比较小的缘故,我就直接暴力求解了。
思路如下:记排序后第n个地区的高度为 h(n);
把地区高度排序,然后一个一个地求前n个地区的平均高度,则前n个地区的最大容水量为 【第n+1个地区的高度 - 前n个地区平均高度】 * n * 100,记为S(n);
所以当S(n) > 水量,就可以知道海拔在 h(n - 1) 到 h(n)之间,然后用 总水量 / 面积( 100 * (n - 1) )得到水的高度,再加上前(n - 1) 个地区的平均高度,即为水的海拔高度。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main()
{
int m,n,height[1000],water,sum[1000];
double average[1000],ans,rate;
int kase = 0;
while(cin >> m >> n && m != 0)
{
kase++;
for(int i = 1; i <= m * n; i++)
scanf("%d",height + i);
cin >> water;
sort(height + 1,height + m * n + 1);
sum[0] = 0;
int i ;
for(i = 1;i <= m * n; i++)
{
sum[i] = sum[i - 1] + height[i];
average[i] = (double)sum[i] / i;
if(((double)height[i] - average[i - 1]) * (i - 1) * 100 > (double)water)
break;
}
rate = (double) (i - 1) / double(m * n);
ans = (double)water /(i - 1) / 100 + average[i - 1];
cout << ans << endl << rate << endl;
}
return 0;
}
- UVa 815
- uva 815
- uva 815
- UVa 815
- UVA 815
- UVa 815
- Flooded! - UVa 815 二分
- 【UVA】815 - Flooded!
- UVA - 815 Flooded
- UVa 815 - Flooded!
- UVA 815 Flooded!
- UVA - 815 Flooded!
- Uva-815 - Flooded!-AC
- UVA 815 Flooded!
- UVA 815(p99)----Flooded!
- UVA 815 Flooded!
- UVa 815 洪水!Flooded!
- UVA - 815 Flooded!
- java中String byte HexString的转换
- Software-Building-HOWTO_2
- Ext.grid.CheckboxSelectionModel()勾选不上
- Java提高篇-----Java集合细节(一):请为集合指定初始容量
- Round #344 (Div. 2) A - Interview
- uva 815
- 在jsp页面判断如果有信息就提示,否则不提示
- mysql,sqlserver及oracle分页查询
- libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
- iOS 用AFNetWorking 判断网络状态
- IOS学习 Notification 用通知传值
- [LeetCode]79. Word Search
- Software-Building-HOWTO_3
- leetcode:Longest Valid Parentheses 【Java】