UVA_815: Flooded!

本博客介绍了一种方法,通过分析特定区域的土地高度和降雨量来预测洪水后的水位高度及其覆盖比例,帮助潜在购房者估算可能的损失。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

To enable homebuyers to estimate the cost of flood insurance, a real-estate firmprovides clients with the elevation ofeach 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 higherelevation will run downhill. For simplicity, we also assume that storm sewers enablewater from high-elevation squaresin valleys (completely enclosed by still higher elevation squares) to drain to lowerelevation squares, and that water willnot be absorbed by the land.
From weather data archives, we know the typical volume of water that collects in aregion. As prospective homebuyers,we wish to know the elevation of the water after it has collected in low-lyingsquares, and also the percentage of theregion's area that is completely submerged (that is, the percentage of 10-metersquares whose elevation is strictly lessthan 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 pairof integers, m and n, each less than 30,giving the dimensions of the rectangular region in 10-meter units. Immediatelyfollowing are m lines of n integers givingthe elevations of the squares in row-major order. Elevations are given in meters,with positive and negative numbersrepresenting elevations above and below sea level, respectively. The final valuein each region description is an integerthat indicates the number of cubic meters of water that will collect in the region.A pair of zeroes follows the descriptionof the last region.

Output

For each region, display the region number (1, 2, ...), the water level (in metersabove or below sea level) and thepercentage of the region's area under water, each on a separate line. The water leveland percentage of the region's areaunder water are to be displayed accurate to two fractional digits. Follow the outputfor 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.


分析:此题解法多种,可以先读取所有网格,然后sort,从第一个开始对海拔差累加算出水的实际海拔,如果比下个网格的海拔小则完成:网格数×当前水海拔 = 水的总高度 + 网格累加和,注意这里的网格是指当前计算的所有网格。


#include <stdio.h>
#include <algorithm>

using namespace std;

const int maxn = 910;
int high[maxn];

bool cmp(int a,int b)
{
	return a<b;
}

int sum(int index)
{
	int s = 0;
	for(int i=0; i<=index; i++)
	{
		s += high[i];
	}
	return s;
}

int main()
{
	int water;
    int m,n;
    int region = 0;
    while(~scanf("%d%d",&m,&n)&&m)
    {
		int len = m*n;
		for(int i=0; i<len; i++)
		{
			scanf("%d",&high[i]);
		}
		scanf("%d",&water);
		double water_h = 1.0*water/100;
		sort(high,high+len,cmp);
		int index = 1;
		double x_h = water_h + high[0];
		while(index<len && x_h>high[index])
		{
			x_h = (water_h+sum(index))/(index+1);
			index++;
		}
		printf("Region %d\n",++region);
		printf("Water level is %.2lf meters.\n",x_h);
		printf("%.2lf percent of the region is under water.\n",100.0*index/len);
		putchar('\n');
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值