蚯蚓

三个队列的想法很妙...

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cmath>
 6 using namespace std;
 7 typedef long long ll;
 8 const ll maxn=8e6+7;
 9 ll n,m,q,u,v,t,tim,h1=1,h2=1,h3=1,t1,t2,t3,atp,rtp;
10 ll a[maxn],q1[maxn],q2[maxn],q3[maxn],ans[maxn],ret[maxn];
11 ll read(){
12   ll x=0,f=1;char s=getchar();
13   while(s<'0'||s>'9'){if(s=='-') f=-1;s=getchar();}
14   while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
15   return f*x;
16 }
17 bool cmp(ll a,ll b){
18   return a>b;
19 }
20 int main(){
21   n=read();m=read();q=read();u=read();v=read();t=read();
22   for(ll i=1;i<=n;i++) q1[i]=read();
23   t1=n;sort(q1+1,q1+n+1,cmp);
24   for(ll i=1;i<=m;i++){
25       int res;
26     /*if(h1<=t1&&q1[h1]>=q2[h2]&&q1[h1]>=q3[h3]) {res=q1[h1];h1++;}
27     else if(q2[h2]>=q1[h1]&&q2[h2]>=q3[h3]) {res=q2[h2];h2++;}
28     else{res=q3[h3];h3++;}*/
29     if(h1>t1){if(q2[h2]>q3[h3])res=q2[h2++];else res=q3[h3++];}
30     else if(q1[h1]>=q2[h2]&&q1[h1]>=q3[h3])res=q1[h1],++h1;
31     else if(q2[h2]>=q3[h3]&&q1[h1]<=q2[h2])res=q2[h2],++h2;
32     else res=q3[h3],++h3;
33     res+=tim;ans[++atp]=res;
34     int tt=res*u/v;int dd=res-tt;
35     tim+=q;
36     tt-=tim;dd-=tim;
37     q2[++t2]=tt;q3[++t3]=dd;
38   }
39   for(ll i=1;i<=m/t;i++) printf("%d ",ans[i*t]); cout<<endl;
40   for(ll i=h1;i<=t1;i++) ret[++rtp]=q1[i]+tim;
41   for(ll i=h2;i<=t2;i++) ret[++rtp]=q2[i]+tim;
42   for(ll i=h3;i<=t3;i++) ret[++rtp]=q3[i]+tim;
43   sort(ret+1,ret+rtp+1,cmp);
44   for(ll i=1;i<=(n+m)/t;i++) printf("%d ",ret[i*t]);
45 } 

这里注释的那一段是因为如果q1为空的话,后面的else if判断是没有意义的...

原文地址:https://www.cnblogs.com/lcan/p/9892152.html