Codeforces Round #390 (Div. 2)B Ilya and tic-tac-toe game
2017-01-22 13:42
295 查看
题目大意:
两个人走三子棋问下一步是否能赢。
题目解法:
枚举所有情况就行了,反正在边上的就8种,在中间的4种。
代码:
两个人走三子棋问下一步是否能赢。
题目解法:
枚举所有情况就行了,反正在边上的就8种,在中间的4种。
代码:
#include "iostream" #include "algorithm" #include "cstdio" #include "math.h" #include "string" #include "string.h" using namespace std; int go[2][4] = { {-1,0,1,0},{0,1,0,-1} }; char mp[10][10]; bool judge(int x, int y) { if (mp[x - 1][y] == 'x'&&mp[x - 2][y] == 'x') { return true; } if (mp[x + 1][y] == 'x'&&mp[x + 2][y] == 'x') { return true; } if (mp[x][y - 1] == 'x'&&mp[x][y - 2] == 'x') { return true; } if (mp[x][y + 1] == 'x'&&mp[x][y + 2] == 'x') { return true; } if (mp[x + 1][y + 1] == 'x'&&mp[x + 2][y + 2] == 'x') { return true; } if (mp[x - 1][y - 1] == 'x'&&mp[x - 2][y - 2] == 'x') { return true; } if (mp[x + 1][y - 1] == 'x'&&mp[x + 2][y - 2] == 'x') { return true; } if (mp[x - 1][y + 1] == 'x'&&mp[x - 2][y + 2] == 'x') { return true; } return false; } bool judge2(int x, int y) { if (mp[x - 1][y] == 'x'&&mp[x + 1][y] == 'x') { return true; } if (mp[x][y - 1] == 'x'&&mp[x][y + 1] == 'x') { return true; } if (mp[x + 1][y + 1] == 'x'&&mp[x - 1][y - 1] == 'x') { return true; } if (mp[x + 1][y - 1] == 'x'&&mp[x - 1][y + 1] == 'x') { return true; } return false; } int main() { for (int i = 2;i <= 5;i++) { for (int j = 2;j <= 5;j++) { scanf(" %c", &mp[i][j]); } } bool flag = false; for (int i = 2;i <= 5;i++) { for (int j = 2;j <= 5;j++) { if (mp[i][j] == 'x') { if (judge(i, j)) { flag = true; break; } } } if (flag) break; } if (!flag) { for (int i = 2;i <= 5;i++) { for (int j = 2;j <= 5;j++) { if (mp[i][j] == '.') { if (judge2(i, j)||judge(i,j)) { flag = true; break; } } } if (flag) break; } } if (flag) puts("YES"); else puts("NO"); return 0; }
相关文章推荐
- Codeforces Round #390 (Div. 2)-B Ilya and tic-tac-toe game(模拟)
- Codeforces Round #390 (Div. 2) B. Ilya and tic-tac-toe game(dfs)
- Codeforces #390 (Div. 2) B. Ilya and tic-tac-toe game ( DFS
- Codeforces Round #390(Div. 2)B. Ilya and tic-tac-toe game【模拟】
- 【codeforces 754B】 Ilya and tic-tac-toe game
- Cdoeforces 754 B - Ilya and tic-tac-toe game
- Codeforces-754B-Ilya and tic-tac-toe game(简单模拟判断)
- 2017寒假集训-小题训练1:F - Ilya and tic-tac-toe game
- B. Ilya and tic-tac-toe game
- Codeforces Round #311 (Div. 2) A. Ilya and Diplomas
- codeforces 754 B Ilya and tic-tac-toe game
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree 树dp 统计
- Codeforces Round #430 (Div. 2) 842C Ilya And The Tree(暴力)
- Codeforces Round #430 (Div. 2)-搜索&STL-Ilya And The Tree
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree dfs+set
- A. Ilya and Diplomas( Codeforces Round #311 (Div. 2) )
- Codeforces Round #297 (Div. 2) C. Ilya and Sticks
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree dfs+set
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree dfs+set