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

Problem A Rook, Bishop and King

题目要求:在国际象棋棋盘上给你一个起始点一个终点。让你求车,象,国王从起始点到终点最短走的步数。

做法很简单三个公式,具体看代码吧。

代码如下:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <algorithm>
 6 #include <utility>
 7 #include <vector>
 8 #include <queue>
 9 #include <stack>
10 
11 using namespace std;
12 
13 int x1, y1, x2, y2;
14 
15 inline int abs(int x){return x>0?x:-x;}
16 
17 int solve1()
18 {
19     if(x1==x2 && y1==y2)return 0;
20     if(x1==x2 || y1==y2)return 1;
21     return 2;
22 }
23 
24 int solve2(){
25     if((x1+x2+y1+y2)%2==1 || (x1==x2 && y1==y2))return 0;
26     if(x1+y1==x2+y2)return 1;
27     if(x1+(9-y1)==x2+(9-y2))return 1;
28     return 2;
29 }
30 
31 int solve3(){
32     return max(abs(x1-x2),abs(y1-y2));
33 }
34 
35 int main()
36 {
37 //    freopen("in.txt", "r", stdin);
38 
39     while(cin >> x1 >> y1 >> x2 >> y2){
40         printf("%d ", solve1());
41         printf("%d ", solve2());
42         printf("%d\n", solve3());
43     }
44     return 0;
45 }
View Code

Problem B Berland Bingo

题目要求:有若干个人每人手中有一些卡片,然后开始报数,没报一个数。拥有这个数卡片的人可以把卡片划掉。当一个人手上所有的卡片都划掉了。就算那个人赢了。如果两个人手上的卡片一起没有那没有人赢。问你最好的情况下第i个人会不会赢。

主要是对于一个人手上的卡片,遍历所有其他人的查看事都有人的卡片是这个人卡片的子集。若有则不会他赢了。

代码如下:

 1 #include <iostream>
 2 #include <fstream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <cstdlib>
 6 #include <cmath>
 7 #include <algorithm>
 8 #include <utility>
 9 #include <vector>
10 #include <queue>
11 #include <stack>
12 #define INF 0x7fffffff
13 #define ll long long
14 #define eps 1e-6
15 
16 using namespace std;
17 
18 int n, m[110], num[110][110], flag1[110], flag2[110];
19 
20 bool judge(int x, int b){
21     memset(flag1, 0 ,sizeof flag1);
22     memset(flag2, 0 ,sizeof flag2);
23     for(int i=0; i<m[x]; i++){
24         flag1[num[x][i]] = 1;
25     }
26     for(int i=0; i<m[b]; i++){
27         flag2[num[b][i]] = 1;
28     }
29     for(int i=0; i<101; i++){
30         if(flag1[i]==0 && flag2[i])return true;
31     }
32     return false;
33 }
34 
35 int main()
36 {
37 //    freopen("in.txt", "r", stdin);
38 
39     while(scanf("%d", &n)!=EOF){
40         for(int i=0; i<n; i++){
41             scanf("%d", &m[i]);
42             for(int j=0; j<m[i]; j++){
43                 scanf("%d", &num[i][j]);
44             }
45         }
46         for(int i=0; i<n; i++){
47             int flag = 1;
48             for(int j=0; j<n; j++){
49                 if(i!=j && judge(i,j)==false){
50                     flag = 0;break;
51                 }
52             }
53             if(flag)printf("YES\n");
54             else printf("NO\n");
55         }
56     }
57     return 0;
58 }
View Code

 

posted @ 2013-12-07 21:37  张小豪  阅读(227)  评论(0编辑  收藏  举报