题目链接
时隔一年多,终于A掉了...
错因:
1.用第二行的写法就会错。(可以不用\(floor\))
- 2.因为队列中的元素需要加上时间戳才是真实的长度,所以会有负的,假如队列一为空,队列二和队列三里的元素都为负,就会取到空队列里的0元素(因为手写的队列,不会\(CE\))。
被这么两个小点卡死了www
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<queue> using namespace std; const int N = 7000005; const int inf = 1e9+7; int q1[N],q2[N],q3[N],ad; //priority_queue<int>ans; int ans[N<<1]; int h1,t1,h2=1,t2,h3=1,t3; int n,m,u,v,p,q,t; bool cmp(int a,int b) { return a>b;} double val; int main() { // freopen("a.in","r",stdin); // freopen("a.out","w",stdout); scanf("%d%d%d%d%d%d",&n,&m,&q,&u,&v,&t); val=(double)u/v; // cout<<val<<endl; for(int i=1;i<=n;i++) scanf("%d",&q1[i]); sort(q1+1,q1+n+1,cmp); h1=1; t1=n; int top,a,b,c,id; // q2[1]=-1; q3[1]=-1; for(int i=1;i<=m;i++) { int qy=0,id=0; a=-inf,b=-inf,c=-inf; if(h1<=t1) a=q1[h1]+ad; if(h2<=t2) b=q2[h2]+ad; if(h3<=t3) c=q3[h3]+ad; if(a>qy) qy=a,id=1; if(b>qy) qy=b,id=2; if(c>qy) qy=c,id=3; if(id==1) ++h1; if(id==2) ++h2; if(id==3) ++h3; /*if((q1[h1]>=q2[h2])||(h2>t2)) { if((q1[h1]>=q3[h3])||(h3>t3)) qy=q1[h1]+ad,h1++; else qy=q3[h3]+ad,h3++; } else { if((q2[h2]>=q3[h3])||(h3>t3)) qy=q2[h2]+ad,h2++; else qy=q3[h3]+ad,h3++; }*/ ad+=q; if(i%t==0) printf("%d ",qy); int a=floor(val*(double)qy),b=qy-a; // int a=qy*u/v,b=qy-a; !!! q2[++t2]=a-ad; q3[++t3]=b-ad; // cout<<endl<<h3<<"*"<<t3<<endl; } printf("\n"); // q1[t1+1]=-1; q2[t2+1]=-1; q3[t3+1]=-1; int tot=0; for(int i=h1;i<=t1;i++) ans[++tot]=q1[i]+ad; for(int i=h2;i<=t2;i++) ans[++tot]=q2[i]+ad; for(int i=h3;i<=t3;i++) ans[++tot]=q3[i]+ad; sort(ans+1,ans+tot+1,cmp); for(int i=1;i<=tot;i++) if(i%t==0) printf("%d ",ans[i]); return 0; }