AcWing 1262. 鱼塘钓鱼

原题链接

考察:堆+枚举+贪心

md完全没想到,我是fw

思路:

        有贪心思想可知,我们可以确定离开当前鱼塘后,去其他鱼塘钓鱼比折返更优.所以我们可以枚举最远到达哪个鱼塘,这样走路的时间就确定了.剩下就是在枚举的鱼塘范围内取最大的T-走路时间的鱼数.

时间复杂度O(n*Tlog2T)

 1 #include <iostream>
 2 #include <cstring>
 3 #include <queue>
 4 using namespace std;
 5 typedef pair<int,int> PII;
 6 const int N = 110;
 7 int a[N],b[N],c[N],n,T;
 8 int solve(int t,int m)
 9 {
10     if(t<=0) return 0;
11     int res = 0;
12     priority_queue<PII,vector<PII>,less<PII> >q;
13     for(int i=1;i<=m;i++) q.push({a[i],i});
14     while(t)
15     {
16         PII it =q.top();
17         q.pop();
18         res+=it.first;
19         it.first=max(it.first-b[it.second],0);
20         q.push(it);
21         t--;
22     }
23     return res;
24 }
25 int main()
26 {
27     int ans= 0;
28     scanf("%d",&n);
29     for(int i=1;i<=n;i++) scanf("%d",&a[i]);
30     for(int i=1;i<=n;i++) scanf("%d",&b[i]);
31     for(int i=2;i<=n;i++) scanf("%d",&c[i]),c[i]+=c[i-1];
32     scanf("%d",&T);
33     for(int i=1;i<=n;i++)
34         ans = max(solve(T-c[i],i),ans);
35     printf("%d\n",ans);
36     return 0;
37 }

 

posted @ 2021-04-14 01:45  acmloser  阅读(58)  评论(0编辑  收藏  举报