Uva 815 Flooded!(脑洞)

题目保证水会从海拔最低的格子开始填。虽说是求水在矩阵中的海拔,但把矩阵拆成一条链,把柱子从低到高排列,再从最低的格子注水,最后的海拔高度也是不会变的。

相当于把水柱从高低排列了。

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
using namespace std;
#define INF 0x7fffffff

int h[35 * 35], n, m;
double v, H, k;

int main()
{
//    freopen("815.in", "r", stdin);

    int cas = 0;
    while(scanf("%d%d", &n, &m), n)
    {
        n *= m;
        for(int i = 0; i < n; i++)
            scanf("%d", h + i);
        h[n] = INF, n++;
        sort(h, h + n);
        scanf("%lf", &v);
        v /= 100.0;
        for(int i = 1; i <= n; i++)
        {
            v += h[i - 1];
            H = v / i;
            if(H < h[i])
            {
                k = i;
                break;
            }
        }
        printf("Region %d\n", ++cas);
        printf("Water level is %.2lf meters.\n", H);
        printf("%.2lf percent of the region is under water.\n\n", 100.0 * k / (n - 1));
    }
    return 0;
}


已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页