____________________________________________________________________________________________________________
tp()函数中的ans一开始初始化大了,然后玄学RE-->TLE-->WA
STL暴力
#include<bits/stdc++.h> using namespace std; priority_queue<int>q; int n,m,qt,u,v,t,a,cnt; double p; int main() { scanf("%d%d%d%d%d%d",&n,&m,&qt,&u,&v,&t);p=(double)u/v; for(int i=1;i<=n;i++){scanf("%d",&a);q.push(a);} for(int i=1;i<=m;i++) { int top=q.top()+(i-1)*qt; q.pop(); int a1=floor(p*(double)top),a2=top-a1; if(i%t==0)cout<<top<<" "; q.push(a1-i*qt);q.push(a2-i*qt); }cout<<endl; while(!q.empty()) { ++cnt; if(cnt%t==0)cout<<q.top()+m*qt<<" "; q.pop(); } }
三队列模拟
#include<bits/stdc++.h> using namespace std; int n,m,qt,u,v,t,a,cnt,tot,h[100100]; double p; int cmp(int a,int b){return a>b;} queue<int>q1;queue<int>q2;queue<int>q3; int tp() { int ans=-2147483647,flg=0; if(!q1.empty()&&ans<q1.front()){ans=q1.front();flg=1;} if(!q2.empty()&&ans<q2.front()){ans=q2.front();flg=2;} if(!q3.empty()&&ans<q3.front()){ans=q3.front();flg=3;} if(flg==1)q1.pop(); if(flg==2)q2.pop(); if(flg==3)q3.pop(); return ans; } int main() { scanf("%d%d%d%d%d%d",&n,&m,&qt,&u,&v,&t); p=(double)u/v; for(int i=1;i<=n;i++){scanf("%d",&h[i]);} sort(h+1,h+1+n,cmp); for(int i=1;i<=n;i++)q1.push(h[i]); for(int i=1;i<=m;i++) { tot=tp()+(i-1)*qt; int a1=floor(p*(double)tot),a2=tot-a1; a1-=i*qt;a2-=i*qt; if(i%t==0)cout<<tot<<" "; q2.push(a1);q3.push(a2); } cout<<endl; while(!q1.empty()||!q2.empty()||!q3.empty()) { ++cnt;tot=tp(); if(cnt%t==0)cout<<tot+m*qt<<" "; } }