奥赛一本通 1431 钓鱼
1431 钓鱼
题目大意
有 $n$ 个钓鱼湖线性排列,在两个湖之间移动需要时间。湖中每个单位时间可以钓到的鱼随钓鱼的时间线性减少,求固定时间中最多的钓鱼数量。
知识要点
贪心、堆
解题思路
显然在到达一个湖后就没必要回头钓第二次,这样只会浪费移动时间。可以先枚举仅在前 $i$ 个湖中钓鱼,计算出移动时间后剩下的都是钓鱼时间,很明显每个单位时间都应该钓鱼量最多的那个湖,使用堆即可获取最大值,然后将减少后的鱼量又放回堆中。
参考代码
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int f[N], d[N], t[N];
int main() {
int n, h, ans = 0;
scanf("%d%d", &n, &h);
for(int i = 0; i < n; i++) scanf("%d", &f[i]);
for(int i = 0; i < n; i++) scanf("%d", &d[i]);
for(int i = 1; i < n; i++) scanf("%d", &t[i]), t[i] += t[i - 1];
for(int i = 0; i < n; i++) {
priority_queue<pair<int, int>> Q;
for(int j = 0; j <= i; j++) Q.push({f[j], d[j]});
int res = 0;
for(int time = h * 12 - t[i]; time > 0 && Q.size(); time--) {
pair<int, int> p = Q.top();
Q.pop();
res += p.first, p.first -= p.second; //钓鱼量减少
if(p.first > 0) Q.push(p);
}
ans = max(ans, res);
}
printf("%d\n", ans);
return 0;
}

浙公网安备 33010602011771号