洛谷P3887 [GDOI2014]世界杯 题解 队列模拟
题目链接:https://www.luogu.com.cn/problem/P3887
解题思路:
一开始给4组人从大到小排序然后放入4个队列,然后每次从队列中选出来人,用4个队列模拟即可。
实现代码如下:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int K, D, M, F,
k[maxn], d[maxn], m[maxn], f[maxn],
Q, a, b, c;
queue<int> que_k, que_d, que_m, que_f;
bool cmp(int a, int b) {
return a > b;
}
int main() {
cin >> K >> D >> M >> F;
for (int i = 0; i < K; i ++) cin >> k[i];
sort(k, k+K, cmp);
for (int i = 0; i < K; i ++) que_k.push(k[i]);
for (int i = 0; i < D; i ++) cin >> d[i];
sort(d, d+D, cmp);
for (int i = 0; i < D; i ++) que_d.push(d[i]);
for (int i = 0; i < M; i ++) cin >> m[i];
sort(m, m+M, cmp);
for (int i = 0; i < M; i ++) que_m.push(m[i]);
for (int i = 0; i < F; i ++) cin >> f[i];
sort(f, f+F, cmp);
for (int i = 0; i < F; i ++) que_f.push(f[i]);
cin >> Q;
while (Q --) {
cin >> a >> b >> c;
long long sum = que_k.front();
long long num = a + b + c + 1;
que_k.pop();
while (a --) {
sum += que_d.front();
que_d.pop();
}
while (b --) {
sum += que_m.front();
que_m.pop();
}
while (c --) {
sum += que_f.front();
que_f.pop();
}
printf("%.2lf\n", (double) sum / (double) num);
}
return 0;
}