CodeForces Round #402 (Div.2) A-E

 2017.2.26 CF D2 402

这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了……

F看了看,不会,弃

E看了看,不会,弃

D看了看,不会……没法再弃了。想了好久发现可以二分答案(浪费30min)

过了D以后去看F,发现果然还是不会(浪费20min)

之后看E,思路跑偏浪费20min+

此时时间还剩大约20min,终于想到了E可能是正解的做法,开始拼手速,各种调试,终于调过了样例,而时间只剩10s了……试图提交,拼手速成功,拼网速失败……

1000+分的差距,有时候只有几秒钟(其实是SX博主前面浪费太多时间,活该)

↑比赛结束后交了一发E,1A,这就更气了……

 

A.Pupils Redistribution

如果分数为x的学生数为奇数,那么无解。

否则把多于平均数量的学生给对面,累计答案

那个cnt似乎没必要

 

 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 int a[mxn],b[mxn];
15 int cnt=0;
16 int main(){
17     int i,j,x;
18     int n=read();
19     for(i=1;i<=n;i++){
20         x=read();
21         a[x]++;
22     }
23     for(i=1;i<=n;i++){
24         x=read();
25         b[x]++;
26     }
27     int ans=0;
28     for(i=1;i<=5;i++){
29         if((a[i]+b[i])&1){
30             printf("-1\n");
31             return 0;
32         }
33         cnt+=(a[i]-(a[i]+b[i])/2);
34         ans+=abs((a[i]-(a[i]+b[i])/2));
35     }
36     if(cnt)printf("-1\n");
37     else{
38         printf("%d\n",ans/2);
39     }
40     return 0;
41 }
A

 

 

B.Weird Rounding

问至少删几个数字可以使得剩下的数能被10的k次方整除

暴力模拟,从尾部开始删。

注意特判只留一个0的情况。

 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 n;int k;
16 int ans;
17 int main(){
18     int i,j;
19     n=read();k=read();
20     LL tmp=n;
21     int len=0;
22     while(tmp){
23         tmp/=10;
24         len++;
25     }
26     ans=len-1;
27     tmp=n;
28     len=0;
29     bool flag=1;
30     while(tmp){
31         if(tmp%10==0)k--,flag=0;
32         else len++;
33         if(!k)break;
34         tmp/=10;
35     }
36     if(k)len=1e8;
37     if(k&&flag)ans++;
38     printf("%d\n",min(ans,len));
39     return 0;
40 }
B

 

C.Dishonest Sellers

贪心?

现在至少买k件物品,剩下的在打折结束后买,问最小花费。

排个序,把现在买收益最大的至少k个买了,剩下的决策何时买

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<queue>
 6 using namespace std;
 7 const int mxn=200010;
 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 a,b,c;
16 }t[mxn];
17 int cmp(node x,node y){
18     return x.c<y.c;
19 }
20 int n,k;
21 int main(){
22     int i,j;
23     n=read();k=read();
24     for(i=1;i<=n;i++){
25         t[i].a=read();
26     }
27     for(i=1;i<=n;i++){
28         t[i].b=read();
29         t[i].c=t[i].a-t[i].b;
30     }
31     sort(t+1,t+n+1,cmp);
32     int ans=0;
33     for(i=1;i<=k;i++){
34         ans+=t[i].a;
35     }
36     for(i=k+1;i<=n;i++){
37         ans+=min(t[i].a,t[i].b);
38     }
39     printf("%d\n",ans);
40     return 0;
41 }
C

 

D.String Game

求最多的取字母次数使得剩下的串中包含目标串

二分取的次数……

我可能是思路太差……见二分答案的题老是看不出来。

花了好久才想起来二分答案,接着分分钟写完

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<queue>
 6 using namespace std;
 7 const int mxn=200010;
 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 int f[mxn];
15 char s[mxn],c[mxn];
16 int t[mxn];
17 int ls,lc;
18 bool solve(int lim){
19     int hd=1;
20     for(int i=1;i<=ls;i++){
21         if(t[i]<=lim)continue;
22         if(s[i]==c[hd])hd++;
23         if(hd>lc)return 1;
24     }
25     return 0;
26 }
27 int main(){
28     int i,j,x;
29     scanf("%s%s",s+1,c+1);
30     ls=strlen(s+1);
31     lc=strlen(c+1);
32     memset(f,0x3f,sizeof f);
33     f[0]=0x3f3f3f3f;
34     for(i=1;i<=ls;i++){
35         x=read();
36         t[x]=i;
37     }
38     int l=0,r=ls,ans=0;
39     while(l<=r){
40         int mid=(l+r)>>1;
41         if(solve(mid)){
42             ans=mid;
43             l=mid+1;
44         }
45         else r=mid-1;
46     }
47     printf("%d\n",ans);
48     return 0;
49 }
D

 

E.Bitwise Formula

字符串处理稍有点麻烦,本质是个贪心问题。

刚开始思路完全跑偏了,写了各种递归,超复杂,半天调不对(估计对了也会T),浪费了半小时

后来发现每个式子中的变量在之前都已经出现了,并且式子中不会出现 [变量 运算 数字]的格式(根本没有好好读题嘛)

@NOI2014 T1 起床困难综合征

把“?”看作第一个出现的变量,依次确定每一位是0还是1←暴力从前到后所有的式子,在"?"确定的情况下后面的变量都能被依次算出来,看"?"的这一位取0还是1可以使得结果中1最多(答案最大)。

 

  1 #include<iostream>
  2 #include<cstdio>
  3 #include<algorithm>
  4 #include<cstring>
  5 #include<queue>
  6 #include<map>
  7 using namespace std;
  8 const int mxn=100010;
  9 int read(){
 10     int 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 struct edge{
 16     int v,nxt,op;
 17 }e[mxn<<1];
 18 int hd[mxn],mct=0;
 19 void add_edge(int u,int v,int op){
 20     e[++mct].v=v;e[mct].nxt=hd[u];e[mct].op=op;hd[u]=mct;return;
 21 }
 22 //
 23 struct node{
 24     string num;
 25     int p1,p2;
 26     int op;
 27 }t[5010];
 28 
 29 //
 30 int f[5010][1010];
 31 int pre[5010];
 32 int op[5010];
 33 map<string,int>mp;
 34 int cnt=0;
 35 int n,m;
 36 string s;
 37 string cut(int st){
 38     string tmp;tmp.clear();
 39     int len=s.size();
 40     for(int i=st;i<len;i++){
 41         if(s[i]==' ')break;
 42         tmp+=s[i];
 43     }
 44     return tmp;
 45 }
 46 int tst(int id){
 47     int res=0;
 48 //    printf("id:%d  f1:%d\n",id,f[1][id]);
 49     for(int i=2;i<=cnt;i++){
 50 //        printf("i:%d  op:%d  p1:%d  p2:%d\n",i,t[i].op,t[i].p1,t[i].p2);
 51         if(t[i].op==-1){
 52 //            printf("num:%d\n",f[i][id]);
 53         }
 54         else{
 55             if(t[i].op==1){
 56                 f[i][id]=f[t[i].p1][id]|f[t[i].p2][id];
 57             }
 58             if(t[i].op==2){
 59                 f[i][id]=f[t[i].p1][id]^f[t[i].p2][id];
 60             }
 61             if(t[i].op==3){
 62                 f[i][id]=f[t[i].p1][id]&f[t[i].p2][id];
 63             }
 64         }
 65 //        printf("  %d\n",f[i][id]);
 66         if(f[i][id]==1)res++;
 67     }
 68 //    printf("res:%d\n",res);
 69     return res;
 70 }
 71 int minif[1020],mxf[1020];
 72 int main(){
 73     int i,j;
 74     n=read();m=read();
 75     memset(op,-1,sizeof op);
 76     mp["?"]=++cnt;
 77     for(i=1;i<=n;i++){
 78         getline(cin,s);
 79 //        cout<<s<<endl;
 80         int st=0,len=s.length();
 81         //
 82         string c=cut(st);
 83 //        cout<<c<<endl;
 84         if(!mp[c])mp[c]=++cnt;
 85         st+=c.length()+1;
 86         string tmp=cut(st);
 87 //        cout<<tmp<<endl;
 88         st+=tmp.length()+1;
 89         //
 90 
 91         if(s.find("XOR")!=string::npos){//2
 92             t[mp[c]].op=2;
 93             string c1=cut(st);
 94             st+=c1.length()+1;
 95             st+=4;
 96             string c2=cut(st);
 97             t[mp[c]].p1=mp[c1];
 98             t[mp[c]].p2=mp[c2];
 99         }
100         else if(s.find("OR")!=string::npos){//1
101             t[mp[c]].op=1;
102             string c1=cut(st);
103 //            cout<<c1<<endl;
104             st+=c1.length()+1;
105             st+=3;
106             string c2=cut(st);
107             t[mp[c]].p1=mp[c1];
108             t[mp[c]].p2=mp[c2];
109         }
110         else if(s.find("AND")!=string::npos){//3
111             t[mp[c]].op=3;
112             string c1=cut(st);
113             st+=c1.length()+1;
114             st+=4;
115             string c2=cut(st);
116             t[mp[c]].p1=mp[c1];
117             t[mp[c]].p2=mp[c2];
118         }
119         else if(s.find("0") || s.find("1")){
120             t[mp[c]].op=-1;
121             string c1=cut(st);
122 //            cout<<c1<<endl;
123             t[mp[c]].num=c1;
124             int len=c1.length();int v=mp[c];
125             for(j=0;j<len;j++){
126                 f[v][j]=c1[len-j-1]-'0';
127             }
128         }
129     }
130     
131     for(i=0;i<m;i++){
132         f[1][i]=1;
133         int t1=tst(i);
134         f[1][i]=0;
135         int t2=tst(i);
136         if(t1<t2){
137             minif[i]=1;
138             mxf[i]=0;
139         }
140         else if(t1==t2){
141             minif[i]=0;
142             mxf[i]=0;
143         }
144         else{
145             minif[i]=0;
146             mxf[i]=1;
147         }
148     }
149     for(i=m-1;i>=0;i--)printf("%d",minif[i]);
150     printf("\n");
151     for(i=m-1;i>=0;i--)printf("%d",mxf[i]);
152     return 0;
153 }
E

差1分钟就能进rank100了,那叫一个气

 

这个时候只有我的过气女团能安慰我了

 

转载于:https://www.cnblogs.com/SilverNebula/p/6445546.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值