Flooded! UVA - 815

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 lowlying 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.

读题之后大意,

模拟最后求水的高度,以及覆盖的级数,

首先,给的(m*n)个数都是距离水平面的高度,最后求得是水平面

都水面的高度。

 

 

 

 

/*
题目理解:
        海拔高度指的是过于水平面的高度,切勿理解为只能装多少水,
从小到大依次积水,即一个海拔高度到里一个海拔高度的差为积水
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int maxn = 1e5+5;
double p[maxn];

int main()
{
    int m,n,z = 0;
    while(scanf("%d%d",&m,&n)&&(n||m))//接下来n排
    {
        double sum;
        for(int i = 0; i < m*n; i++)
            scanf("%lf",&p[i]);
        scanf("%lf",&sum);
        sum /= 100.0;
        sort(p,p+m*n);
        double hi = 0,cnt = 1;
        for(int i = 0; i < m*n; i++)
        {
            if(i != m*n-1)
			{
				if((p[i+1]-p[i])*(i+1) < sum)
					sum-=(p[i+1]-p[i] )*(i+1); //小就剪掉 
				else
				{
					hi = sum/(i+1); //超过的部位平摊 
					hi+=p[i]; //加上当前位置 
					cnt = (double)(i+1)/(double)(m*n);
					cnt*=100.0; 
					break;
				}
			}
			else
			{
				hi = sum/(i+1);
				hi+=p[i];
				cnt = 100.0;
			}
        }
        printf("Region %d\n",++z);
        printf("Water level is %.2f meters.\n",hi);
        printf("%.2f percent of the region is under water.\n",cnt);
        cout<<endl;
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值