2019 GDUT Rating Contest III : Problem C. Team Tic Tac Toe
题面:
C. Team Tic Tac Toe
COW
XXO
ABC
题目描述:
题目分析:
1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <cmath>
5 #include <set>
6 #include <algorithm>
7 using namespace std;
8 char mymap[5][5];
9 char temp[5][5];
10 int vis[128][128];
11
12 bool check(char ch){
13 int flag;
14 for(int i = 0; i < 3; i++){
15 flag = 1;
16 for(int j = 0; j < 3; j++){
17 if(ch != temp[i][j]) flag = 0;
18 }
19 if(flag) return true;
20 }
21
22 for(int j = 0; j < 3; j++){
23 flag = 1;
24 for(int i = 0; i < 3; i++){
25 if(ch != temp[i][j]) flag = 0;
26 }
27 if(flag) return true;
28 }
29
30 flag = 1;
31 for(int i = 0; i < 3; i++){
32 if(temp[i][i] != ch) flag = 0;
33 }
34 if(flag) return true;
35
36 flag = 1;
37 for(int i = 0; i < 3; i++){
38 if(temp[i][2-i] != ch) flag = 0;
39 }
40 if(flag) return true;
41
42 return false;
43 }
44
45 void reback(){
46 for(int i = 0; i < 3; i++){
47 for(int j = 0; j < 3; j++){
48 temp[i][j] = mymap[i][j];
49 }
50 }
51 }
52
53 void cover(char a, char b){
54 for(int i = 0; i < 3; i++){
55 for(int j = 0; j < 3; j++){
56 if(temp[i][j] == a) temp[i][j] = b;
57 }
58 }
59 }
60
61 void test(){
62 cout <<endl;
63 for(int i = 0; i < 3; i++){
64 for(int j = 0; j < 3; j++){
65 cout << temp[i][j];
66 }
67 cout << endl;
68 }
69
70 }
71
72 int main(){
73 for(int i = 0; i < 3; i++){
74 cin >> mymap[i];
75 }
76
77 reback();
78 //test();
79
80
81 char st[15];
82 int top = 0;
83
84 int cnt1 = 0;
85 for(char i = 'A'; i <= 'Z'; i++){
86 if(check(i)) { cnt1++; st[top++] = i;}
87 }
88 cout << cnt1 << endl;
89
90 for(int i = 0; i < top; i++){
91 int u1 = st[i];
92 for(int j = 0; j < top; j++){
93 int u2 = st[j];
94 vis[u1][u2] = vis[u2][u1] = 1;
95 }
96 }
97
98 int cnt = 0;
99
100
101 for(int ai = 0; ai < 3; ai++){
102 for(int aj = 0; aj < 3; aj++){
103 char ch1 = mymap[ai][aj];
104
105 for(int bi = 0; bi < 3; bi++){
106 for(int bj = 0; bj < 3; bj++){
107 char ch2 = mymap[bi][bj];
108 reback();
109 cover(ch1, ch2);
110
111 //test();
112 if(check(ch2) && !vis[ch1][ch2]) {
113 cnt++;
114 vis[ch1][ch2] = vis[ch2][ch1] = 1;
115 }
116 }
117 }
118 }
119 }
120
121 cout << cnt << endl;
122 return 0;
123 }



1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <cmath>
5 #include <set>
6 #include <map>
7 #include <algorithm>
8 using namespace std;
9 char g[5][5]; //图
10 int G[5][5]; //转化为整数
11 int win[30], win2[30][30]; //标记数组
12
13 void check(int a, int b, int c){
14 if(a == b && b == c) win[a] = 1; //对应一头牛“赢”的情况
15 else if(a == b && b != c) //下面两个个else if都是其中两头牛组队赢的情况
16 win2[a][c] = win2[c][a] = 1; //双向都要标记一下,去重的关键
17 else if(a == c && b != c)
18 win2[a][b] = win2[b][a] = 1;
19 else if(b == c && a != c)
20 win2[b][a] = win2[a][b] = 1;
21 }
22
23 int main(){
24 for(int i = 0; i < 3; i++) cin >> g[i];
25
26 for(int i = 0; i < 3; i++){
27 for(int j = 0; j < 3; j++){
28 G[i][j] = g[i][j]-'A'; //把字母转化为对应的数字,方便开数组
29 }
30 }
31
32 for(int i = 0; i < 3; i++){
33 check(G[i][0], G[i][1], G[i][2]); //每行
34 check(G[0][i], G[1][i], G[2][i]); //每列
35 }
36
37 check(G[0][0], G[1][1], G[2][2]); //正对角线
38 check(G[0][2], G[1][1], G[2][0]); //负对角线
39
40 int ans = 0;
41 for(int i = 0; i < 26; i++) ans += win[i]; //统计一头牛“赢”的情况
42
43 int ans2 = 0;
44 for(int i = 0; i < 26; i++){ //统计两头牛组队后“赢”的情况
45 for(int j = i+1; j < 26; j++){ //去重关键,只要遍历比i大的牛就行了
46 ans2 += win2[i][j];
47 }
48 }
49
50 cout << ans << endl << ans2 << endl;
51 return 0;
52 }
2019 GDUT Rating Contest III : Problem C. Team Tic Tac Toe的更多相关文章
- 2019 GDUT Rating Contest III : Problem D. Lemonade Line
题面: D. Lemonade Line Input file: standard input Output file: standard output Time limit: 1 second Memo ...
- 2019 GDUT Rating Contest III : Problem E. Family Tree
题面: E. Family Tree Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 2019 GDUT Rating Contest III : Problem A. Out of Sorts
题面: 传送门 A. Out of Sorts Input file: standard input Output file: standard output Time limit: 1 second M ...
- 2019 GDUT Rating Contest II : Problem F. Teleportation
题面: Problem F. Teleportation Input file: standard input Output file: standard output Time limit: 15 se ...
- 2019 GDUT Rating Contest I : Problem B. Teamwork
题面: 传送门 B. Teamwork Input file: standard input Output file: standard output Time limit: 1 second Memor ...
- 2019 GDUT Rating Contest I : Problem H. Mixing Milk
题面: H. Mixing Milk Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 2019 GDUT Rating Contest I : Problem A. The Bucket List
题面: A. The Bucket List Input file: standard input Output file: standard output Time limit: 1 second Me ...
- 2019 GDUT Rating Contest I : Problem G. Back and Forth
题面: G. Back and Forth Input file: standard input Output file: standard output Time limit: 1 second Mem ...
- 2019 GDUT Rating Contest II : Problem G. Snow Boots
题面: G. Snow Boots Input file: standard input Output file: standard output Time limit: 1 second Memory ...
随机推荐
- 关于rand()
虽然很早就知道rand是伪随机了,但是一般都懒得用srand. 直到模拟银行家算法时不用srand就造成数据实在有点假(-_-||) 所以要记得srand((int)time(0))啊
- 牛客网-n的约数【dfs】
题目描述:戳这里 解题思路:这题思路好想,n最多也就是20个不同的素数相乘,把所有可能的素数找到,然后枚举素数个数就行了. n = p1^q1 + p2^q2 + p3 ^q3 + ... + pi ...
- PAT L2-004. 这是二叉搜索树吗?【前序遍历转化为后序遍历】
一棵二叉搜索树可被递归地定义为具有下列性质的二叉树:对于任一结点, 其左子树中所有结点的键值小于该结点的键值: 其右子树中所有结点的键值大于等于该结点的键值: 其左右子树都是二叉搜索树. 所谓二叉搜索 ...
- CSS字体大小: em与px、pt、百分比之间的对比
CSS样式最混乱的一个方面是应用程序中文本扩展的font-size属性.在CSS中,你可以用四个不同的单位度量来显示在web浏览器中的文本大小.这四个单位哪一种最适合Web? 这个问题引起了广泛的 ...
- 使用 js 实现一个简易版的模版引擎
使用 js 实现一个简易版的模版引擎 regex (function test() { this.str = str; })( window.Test = ...; format() { let ar ...
- 使用 js 实现一个简易版的 drag & drop 库
使用 js 实现一个简易版的 drag & drop 库 具有挑战性的前端面试题 H5 DnD js refs https://www.infoq.cn/article/0NUjpxGrqRX ...
- moment.js & convert timestamps to date string in js
moment.js & convert timestamps to date string in js https://momentjs.com/ moment().format('YYYY- ...
- 基本ILS面的评估
一.定义与用途 基本ILS面是ICAO DOC8168飞行程序设计规范中提到的一种限制面. 它相当于附件14中代码为3或4的精密进近跑道所规定的障碍物限制面的子集. 包含:进近面(分为两部分).过渡面 ...
- 磁盘使用率/文件大小查看指南du & df
一.前言 磁盘使用率,文件大小查看是我们日常使用命令.这两个是配合使用的,磁盘使用率过高告警了,那么得找到对应的磁盘(df),然后找到对应磁盘下的哪个目录和文件占用了空间(du). df(Disk f ...
- Java中print、printf、println的区别
Java中print.printf.println的区别 区别 print:标准输出,但不换行,不可以空参: println:标准输出,但会自动换行,可以空参,可以看做:println()相当于pri ...