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 = ;
int main() {
int kase = ;
while (cin >> n >> m && (n || m)) {
//if (first)first = 0; else cout << endl;
printf("Region %d\n", ++kase);
priority_queue<double> Q;
rep(i, , n*m) {
double x;
cin >> x;
Q.push(-x);
}
double btm = -Q.top();
double sum; cin >> sum;
double num = , vol = , ele = ;
while (!Q.empty()) {
double now = -Q.top();
int cnt = ;
while (!Q.empty() && now == -Q.top())Q.pop(), cnt++;
num += cnt;
if (Q.empty()) {
ele += sum / / num; break;
}
double d = -Q.top() - now; if (d * * num < sum)sum -= d * * num, ele += d;
else {
ele += sum / / num; break;
} }
printf("Water level is %.2lf meters.\n%.2lf percent of the region is under water.\n\n", btm + ele, num / n / m * );
}
}