Codeforces Round #281 (Div. 2) 解题报告

题目地址:http://codeforces.com/contest/493

A题

  写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可以再出现,但不能再参与计算,这里需要开一个flag数组判重 。打比赛时要调整好心态

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<string.h>
 4 #include<stdlib.h>
 5 #include<stdbool.h>
 6 #include<cmath>
 7 #include<algorithm>
 8 #include<time.h>
 9 
10 using namespace std;
11 #define rep(i,a,b)  for(int i=(a);i<=(b);i++)
12 #define clr(x,y)    memset(x,y,sizeof(x))
13 #define sqr(x)      ((x)*(x))
14 #define LL          long long
15 char sth[100],sta[100];
16 int  num[200][50];
17 bool flag[100][100];
18 
19 int main()
20 {
21     int t,ni,n,i;
22     char p1[3],p2[3],name[100];
23 
24     scanf("%s",sth);
25     scanf("%s",sta);
26     scanf("%d",&n);
27     clr(flag,0);
28     
29     while(n--) {
30         scanf("%d%s%d%s",&t,p1,&ni,p2);
31         if(p2[0]=='y') {
32             if(!num[ni][p1[0]-'a']) {
33                 num[ni][p1[0]-'a']++;
34             } else {
35                 if(!flag[ni][p1[0]-'a']){
36                     if(p1[0]=='h') printf("%s ",sth);
37                     else           printf("%s ",sta);
38                     printf("%d %d\n",ni,t);
39                     flag[ni][p1[0]-'a']=1;
40                 }
41             }
42         } else {
43              if(!flag[ni][p1[0]-'a']){
44                 if(p1[0]=='h') printf("%s ",sth);
45                 else           printf("%s ",sta);
46                 printf("%d %d\n",ni,t);
47                 flag[ni][p1[0]-'a']=1;
48             }
49         }
50     }
51     
52     return 0;
53 }

 

B题

  出现了一个 lexicographically greater的规则。读了很多遍题后才明白题意,其实就是比较两个序列的字典序,浪费了大量时间。首先比较得分大小,得分大的输出。得分相同则比较两个序列的字典序,如果字典序相同,最后一个是谁赢就输出谁。英语读题能力亟待提高。

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<string.h>
 4 #include<stdlib.h>
 5 #include<stdbool.h>
 6 #include<cmath>
 7 #include<algorithm>
 8 #include<time.h>
 9 using namespace std;
10 #define rep(i,a,b)  for(int i=(a);i<=(b);i++)
11 #define clr(x,y)    memset(x,y,sizeof(x))
12 #define sqr(x)      ((x)*(x))
13 #define LL          long long
14 
15 const int N=2*1e5+3511;
16 
17 int n,x;
18 int num1[N],num2[N],head1,head2;
19 LL sum1=0,sum2=0;
20 
21 int check(int a,int b)
22 {
23     int i;
24     int m=min(a,b);
25     for(int i=1;i<=m;i++) {
26         if(num1[i]>num2[i]) {
27             puts("first");
28             exit(0);
29         }
30         if(num1[i]<num2[i]) {
31             puts("second");
32             exit(0);
33         }
34     }
35     
36     if(a>b) puts("first");
37     else {
38        if(a==b) {
39             if(x<0) puts("second");
40             else    puts("first");
41         }
42         if(a<b)    
43         puts("second");
44     }
45     
46     
47 }
48 
49 int main()
50 {
51     head1=0; head2=0;
52     scanf("%d",&n);
53     while(n--) {
54         cin>>x;
55         if(x>0) {
56             head1++;
57             num1[head1]=x;
58             sum1+=x;
59         } else {
60             head2++;
61             num2[head2]=-x;
62             sum2+=-x;
63         }
64     }
65       
66         if(sum1!=sum2) {
67             if(sum1>sum2) puts("first");
68             else puts("second");
69         } else {
70                check(head1,head2); 
71         }
72         
73     
74     
75     return 0;
76 }

 

C题

二分查找三分线距离,使得一队得分减二队得分最大。

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<string.h>
 4 #include<stdlib.h>
 5 #include<stdbool.h>
 6 #include<cmath>
 7 #include<algorithm>
 8 #include<time.h>
 9 using namespace std;
10 #define rep(i,a,b)  for(int i=(a);i<=(b);i++)
11 #define clr(x,y)    memset(x,y,sizeof(x))
12 #define sqr(x)      ((x)*(x))
13 #define LL          long long
14 const int N=2e5+3511;
15 int a[N],b[N],c[2*N];
16 
17 int main()
18 {
19     int n,m,p,t1,t2,s1,s2;
20     LL ret1,ret2,maxi=-1000000000LL;
21     scanf("%d",&n);
22     for(int i=0;i<n;i++) {
23         scanf("%d",&a[i]);
24         c[i]=a[i];
25     }
26     scanf("%d",&m);
27     for(int i=0;i<m;i++) {
28         scanf("%d",&b[i]);
29         c[n+i]=b[i];
30     }
31     
32     sort(a,a+n);sort(b,b+m);sort(c,c+m+n+1);
33     
34     for(int i=0;i<n+m+1;i++) {
35         p=c[i];
36         t1=upper_bound(a,a+n,p)-a;
37         s1=2*t1+3*(n-t1);
38         t2=upper_bound(b,b+m,p)-b;
39         s2=2*t2+3*(m-t2);
40         if(s1-s2>maxi) {
41             maxi=s1-s2;
42             ret1=s1;ret2=s2;
43         }
44     }
45     
46     cout<<ret1<<":"<<ret2<<endl;
47 
48     
49     return 0;
50 }

 

D题

  思维题。有一个N*N的棋盘(2 ≤ n ≤ 10^9) 左上角(1,1)有一个白皇后,右上角(1,n)一个黑色皇后,其它地方填满小兵。每次可以吃掉小兵或对方皇后。如果上下左右对角线相邻,则下一步就可以把对方吃掉。谁先吃掉对方皇后谁就赢。如果黑皇后赢,输出“black”,白皇后赢输出“white”,然后输出第一步走到的坐标(r,c)。If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c

  N分奇数和偶数两种情况讨论。两个人都采用最聪明的策略。每一步则想办法让对方是必败态。则棋手每次下完后保持与对方坐标距离(abs(x1-x2)+abs(y1-y2))是偶数即可。所以N为奇数,黑色赢;N为偶数,白色赢。综上规则,white赢时第一步走的坐标肯定是(1,2)

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<string.h>
 4 #include<stdlib.h>
 5 #include<stdbool.h>
 6 #include<cmath>
 7 #include<algorithm>
 8 #include<time.h>
 9 using namespace std;
10 #define rep(i,a,b)  for(int i=(a);i<=(b);i++)
11 #define clr(x,y)    memset(x,y,sizeof(x))
12 #define sqr(x)      ((x)*(x))
13 #define LL          long long
14 
15 int main()
16 {
17     int n;
18     
19     scanf("%d",&n);
20     if(n & 1) puts("black");
21     else puts("white\n1 2");
22     
23     return 0;
24 }

 

posted @ 2014-12-04 22:06  SXISZERO  阅读(177)  评论(0编辑  收藏  举报