【每日一题】Flooded! UVA - 815 模拟阅读格式题

https://cn.vjudge.net/problem/UVA-815

题意:给你一个矩阵,每个格子的数代表一个海拔并且每个格子的面积100平方米。给你整个区域的降水量(立方米),问降水量(米)。

题解:题目讲了一大堆,唯一关键就是排水系统保证水会从最低的开始淹没。所以直接从小到大不断模拟淹没即可。我用了priorityQ来维护,一个细节是一样海拔的要一起淹没。

坑点:一些无聊的人在vjudge下面xjb讨论,让我wa了好久orz

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<string>
#include<bitset>
#include<queue>

#define re register
#define rep(i,s,t) for(re int i=s;i<=t;++i)
#define per(i,s,t) for(re int i=s;i>=t;--i)
#define mmm(f,x) memset(f,x,sizeof f)
//#define x first
//#define xx second
using namespace std;

typedef  long long ll;
int n, m;
int first = 1;
int main() {
    int kase = 0;
    while (cin >> n >> m && (n || m)) {
        //if (first)first = 0; else cout << endl;
        printf("Region %d\n", ++kase);
        priority_queue<double> Q;
        rep(i, 1, n*m) {
            double x;
            cin >> x;
            Q.push(-x);
        }
        double btm = -Q.top();
        double sum; cin >> sum;
        double num = 0, vol = 0, ele = 0;
        while (!Q.empty()) {
            double now = -Q.top();
            int cnt = 0;
            while (!Q.empty() && now == -Q.top())Q.pop(), cnt++;
            num += cnt;
            if (Q.empty()) {
                ele += sum / 100 / num; break;
            }
            double d = -Q.top() - now;
            
            if (d * 100 * num < sum)sum -= d * 100 * num, ele += d;
            else {
                ele += sum / 100 / num; break;
            }

        }
        printf("Water level is %.2lf meters.\n%.2lf percent of the region is under water.\n\n", btm + ele, num / n / m * 100);
    }
}

 

posted @ 2018-08-20 19:36  SuuTTT  阅读(303)  评论(0编辑  收藏  举报