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

相关文章: