uva 815

来源:互联网 发布:淘宝被处罚了怎么办 编辑:程序博客网 时间:2024/06/12 18:34
Flooded!
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu

Submit Status

Description

Download as PDF

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

0 0
原创粉丝点击