Codeforces Round #398 (Div. 2) A-E

分数史上新低

开场5分钟过了A题,想着这次赌一把手速,先去切C吧

看完C题觉得这应该是道水题,码了十分钟提交,WA

想着这明明是道水题,估计少考虑了情况,添了几行再交,WA

不可能啊,这题都A不掉,和SB有什么区别

(开始半小时后)A不掉啊,要不去做别的题吧,啊不行,不能对不起我写了这么久的代码,继续debug

(开始一小时后)心态崩了,辣鸡比赛我不玩了。关了CF跑去写了半道主席树

(倒数半小时)反正要掉分,今天和这C题死磕吧

(结束看题解)结论:我和SB有什么区别

(第二天写BDE题)卧槽这么简单我为什么看都没看,我和SB有什么区别*3

 

A. Snacktower

 要搭一座数字下面大上面小的树塔,但数字出现的顺序不定。

每个时刻拿到一个数字,不能堆到塔上就扔到堆里,能就建塔

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<queue>
 6 using namespace std;
 7 const int mxn=100010;
 8 int read(){
 9     int x=0,f=1;char ch=getchar();
10     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
11     while(ch>='0' && ch<='9'){x=x*10-'0'+ch;ch=getchar();}
12     return x*f;
13 }
14 priority_queue<int>q;
15 bool f[mxn];
16 int main(){
17     int i,j,x;
18     int n=read();
19     f[n+1]=1;
20     for(i=1;i<=n;i++){
21         x=read();
22         q.push(x);
23         while(!q.empty() && f[q.top()+1]){
24             f[q.top()]=1;
25             printf("%d ",q.top());
26             q.pop();
27         }
28         printf("\n");
29     }
30     return 0;
31 }
A

 

 

B.The Queue

模拟,贪心找到一个适合的插入点。

如果所有人都处理完了,营业还没结束,那主角可以等到最后再过去

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<queue>
 6 #define LL long long
 7 using namespace std;
 8 const int mxn=100010;
 9 LL read(){
10     LL x=0,f=1;char ch=getchar();
11     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
12     while(ch>='0' && ch<='9'){x=x*10-'0'+ch;ch=getchar();}
13     return x*f;
14 }
15 LL ts,tf,t;
16 LL w[mxn];
17 int main(){
18     int i,j;
19     ts=read();tf=read();
20     t=read();
21     int n=read();
22     for(i=1;i<=n;i++){w[i]=read();}
23     if(w[1]>ts){printf("%I64d\n",ts);return 0;}
24     LL ans=1e15,pos=-1;
25     LL smm=ts,last=0;
26     for(i=1;i<=n;i++){
27         last=smm-w[i]+1;
28         if(last<=0){
29             printf("%I64d\n",w[i]-1);
30             return 0;
31         }
32         if(smm+t>tf)break;
33         if(last<ans){
34             ans=last;pos=w[i]-1;
35         }
36         smm+=t;
37     }
38     if(smm+t<=tf)pos=smm;
39     printf("%I64d\n",pos);
40     return 0;
41 }
B

 

 C. Garland

把一棵树分成权值和相等的三部分

明明只是一个DFS?

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<queue>
 6 using namespace std;
 7 const int mxn=1000100;
 8 int read(){
 9     int x=0,f=1;char ch=getchar();
10     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
11     while(ch>='0' && ch<='9'){x=x*10-'0'+ch;ch=getchar();}
12     return x*f;
13 }
14 struct edge{
15     int v,nxt;
16 }e[mxn<<1];
17 int hd[mxn],mct=0;
18 void add_edge(int u,int v){
19     e[++mct].v=v;e[mct].nxt=hd[u];hd[u]=mct;return;
20 }
21 int w[mxn];
22 int sz[mxn];
23 int n,smm=0,rt;
24 int ans[5],cnt=0;
25 int f[mxn];
26 void DFS(int u){
27     f[u]=0;
28     sz[u]+=w[u];
29     for(int i=hd[u];i;i=e[i].nxt){
30         int v=e[i].v;
31         DFS(v);
32         sz[u]+=sz[v];
33 //        if(sz[v]==smm){f[v]=v;}
34         if(f[u] && f[v]){
35             ans[1]=f[u];
36             ans[2]=f[v];
37         }
38         if(f[v])f[u]=f[v];
39     }
40 /*
41     cnt=0;
42     for(int i=hd[u];i;i=e[i].nxt){
43         int v=e[i].v;
44         if(f[v]){
45             f[u]=f[v];
46             if(f[v]!=ans[1])ans[++cnt]=f[v];
47             if(cnt==2){
48                 printf("%d %d\n",ans[1],ans[2]);
49                 exit(0);
50             }
51         }
52     }
53     if(u!=rt && u!=ans[1] && smm*2==sz[u] && cnt){
54         printf("%d %d\n",u,ans[1]);exit(0);
55     }
56     if(sz[u]==smm)f[u]=u;
57 */
58     if(u!=rt && sz[u]==smm*2 && f[u]){
59         ans[1]=u;
60         ans[2]=f[u];
61     }
62     if(sz[u]==smm)f[u]=u;
63     return;
64 }
65 int main(){
66     int i,j,u,v;
67     n=read();
68     for(i=1;i<=n;i++){
69         u=read();v=read();
70         if(!u)rt=i;
71         else add_edge(u,i);
72         w[i]=v;smm+=v;
73     }
74     if(smm%3){printf("-1\n");return 0;}
75     smm/=3;
76     DFS(rt);
77     if(ans[1])printf("%d %d\n",ans[1],ans[2]);
78     else printf("-1\n");
79     return 0;
80 }
C

 

D. Cartons of milk

排序+二分答案

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<queue>
 6 using namespace std;
 7 const int mxn=1000100;
 8 int read(){
 9     int x=0,f=1;char ch=getchar();
10     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
11     while(ch>='0' && ch<='9'){x=x*10-'0'+ch;ch=getchar();}
12     return x*f;
13 }
14 struct node{
15     int w,id;
16 }a[mxn],b[mxn];
17 int cmp(const node a,const node b){
18     return a.w<b.w;
19 }
20 int n,m,k;
21 bool check(int lim){
22     int i,j;
23     int day=0,now=0;
24     for(i=1,j=m-lim+1;i<=n || j<=m; ){
25         if(i<=n && (j>m || a[i].w<=b[j].w)){
26             now++;
27             if(now>k){now-=k;day++;}
28             if(a[i].w<day)return 0;
29             i++;
30         }
31         else{
32             now++;
33             if(now>k){now-=k;day++;}
34             if(b[j].w<day)return 0;
35             j++;
36         }
37     }
38     return 1;
39 }
40 int main(){
41     int i,j;
42     n=read();m=read();k=read();
43     for(i=1;i<=n;i++){a[i].w=read();}
44     for(i=1;i<=m;i++){b[i].w=read();b[i].id=i;}
45     sort(a+1,a+n+1,cmp);
46     sort(b+1,b+m+1,cmp);
47     int l=0,r=m,ans=0;
48     while(l<=r){
49         int mid=(l+r)>>1;
50         if(check(mid)){
51             ans=mid;
52             l=mid+1;
53         }
54         else r=mid-1;
55     }
56     if(!ans)if(!check(0))ans=-1;
57     printf("%d\n",ans);
58     for(i=m-ans+1;i<=m;i++){
59         printf("%d ",b[i].id);
60     }
61     return 0;
62 }
D

 

E. Change-free

起初有个脑洞,先每次都付纸币,然后贪心找不满度最大的日子“退流”。对正确性没有自信,悄悄看了看dalao们的代码,发现写法都是每次付硬币,然后贪心找不满度最小的日子改付纸币。

后一种好写,就写后一种咯

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<queue>
 6 using namespace std;
 7 const int mxn=100010;
 8 int read(){
 9     int x=0,f=1;char ch=getchar();
10     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
11     while(ch>='0' && ch<='9'){x=x*10-'0'+ch;ch=getchar();}
12     return x*f;
13 }
14 struct cmp{
15     int w,id;
16     friend bool operator < (const cmp a,const cmp b){
17         return a.w>b.w;
18     }
19 };
20 priority_queue<cmp> q;
21 bool note[mxn];
22 int n,m;
23 int c[mxn],w[mxn];
24 long long ans=0;
25 void solve(){
26     int i,j;
27     for(i=1;i<=n;i++){
28         int cost=c[i]%100;if(!cost)continue;
29         int res=100-cost;
30 //        printf("res:%d\n",res*w[i]);
31         q.push((cmp){res*w[i],i});
32         m-=cost;
33         while(m<0){
34             cmp tmp=q.top();q.pop();
35             ans+=tmp.w;
36             note[tmp.id]^=1;
37             m+=100;
38         }
39     }
40     return;
41 }
42 int main(){
43     int i,j;
44     n=read();m=read();
45     for(i=1;i<=n;i++)c[i]=read();
46     for(j=1;j<=n;j++)w[j]=read();
47     solve();
48     printf("%I64d\n",ans);
49     for(i=1;i<=n;i++){
50         if(note[i])printf("%d %d\n",(c[i]+99)/100,0);
51         else printf("%d %d\n",c[i]/100,c[i]%100);
52     }
53     return 0;
54 }
E

 

posted @ 2017-02-19 17:02  SilverNebula  阅读(183)  评论(0编辑  收藏  举报
AmazingCounters.com