标签:大小 fish div i++ png return src pac class
为什么要考虑每个时刻呢,考虑每条鱼什么时候被吃不就行了吗,至于时刻相同编号大小的问题,用pair不就可以吗
1 #include <bits/stdc++.h> 2 using namespace std; 3 pair<int,int> a[200005],p; 4 int NOW,i,n,m,x,now; 5 int cmp(pair<int,int> i,pair<int,int> j) {return i.first>j.first || i.first==j.first && i.second>j.second;} 6 int main() 7 { 8 freopen("fish.in","r",stdin); 9 freopen("fish.out","w",stdout); 10 while (cin>>m) 11 { 12 cin>>n>>x; 13 NOW=0; now=0; 14 for (i=1; i<=n; i++) 15 { 16 scanf("%d",&a[i].second); 17 a[i].first=a[i].second; 18 push_heap(a+1,a+i+1,cmp); 19 if (i<=m) now++; 20 } 21 for (i=1; i<=m; i++) 22 { 23 if (!now) break; 24 if (a[1].first>x) break; 25 p = a[1]; 26 pop_heap(a+1,a+now+1,cmp); 27 NOW++; now--; 28 if (p.first<x && now+NOW<m) 29 { 30 now++; 31 a[now]=p; a[now].first+=a[now].second; 32 push_heap(a+1,a+now+1,cmp); 33 } 34 } 35 cout<<m-now-NOW<<‘ ‘<<now<<endl; 36 } 37 return 0; 38 }
标签:大小 fish div i++ png return src pac class
原文地址:https://www.cnblogs.com/lcan/p/9903393.html