标签:sci time note help regular dia als initial 一起
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
标签:sci time note help regular dia als initial 一起
原文地址:https://www.cnblogs.com/happy-MEdge/p/10426190.html