UVa815:Flooded(洪水)

本文介绍了一个关于洪水模拟的问题,通过给定地区的地形数据和预计的降雨量,计算出洪水达到的水平高度及被淹没土地的百分比。采用排序算法优化计算过程。

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

UVa815洪水Flooded!
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.

有一个n×m的网格,每个格子是边长10米的正方形,网格四周是无限大的墙壁。
输入每个格子的海拔高度,以及网格内雨水的总体积。
输出水位的海拔高度以及有多少百分比的区域有水(即高度严格小于水平面)。

今天这题a的甚是痛苦,迷之wa,还好最后ac了。。。。
主要思路就是将海拔高度排序。
代码如下:

`#include

include

include

include

using namespace std;

int main()
{
int n, m,l=0;
double hai[1000];
while(cin >> n >> m&&n&&m)
{
for (int i = 0; i < m*n; i++)
cin >> hai[i];
sort(hai, hai + m*n);
int T,flag=0;
double t,k,h;
cin >> T;
t=T;
for (int i = 0; i < n*m; i++)
{
t = t + 100*hai[i];

        k = t / (100.0 * (i + 1));

        if (k <= hai[i + 1])
        {
            h = i;
            flag=1;
            break;
        }
    }
    if(!flag) h=n*m-1;
    printf("Region %d\n",++l);
    printf("Water level is %.2f meters.\n",k);
    printf("%.2f percent of the region is under water.\n\n",(((h+1)*1.0) / (n*m))*100);
}
return 0;

}
`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值