codeforces 754 B Ilya and tic-tac-toe game
来源:互联网 发布:软件怎么销售 编辑:程序博客网 时间:2024/05/19 13:07
题目描述:
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first getsthree of his signs in a row next to each other (horizontal, vertical or diagonal).
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letterx), or 'o' (lowercase English lettero). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
xx...oo.x...oox.
YES
x.oxox..x.o.oo.x
NO
x..x..ooo...x.xo
YES
o.x.o....x..ooxx
NO
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn.
题目大意:
类似于五子棋的问题
题目分析:
暴力模拟,这里我把数组开成8*8就可以尽情的讨论啦,不用考虑数组溢出的问题,只需要讨论你放的这个点是顶点(米字)还是中点(十字)
AC代码:
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<cstdlib>using namespace std;const int maxn=8;char map[maxn][maxn];int v[maxn][maxn];bool search(int x,int y){ if((v[x-2][y-2]&&v[x-1][y-1])||(v[x-2][y]&&v[x-1][y])||(v[x-2][y+2]&&v[x-1][y+1])||(v[x][y-2]&&v[x][y-1])||(v[x][y+2]&&v[x][y+1])||(v[x+2][y-2]&&v[x+1][y-1])||(v[x+2][y]&&v[x+1][y])||(v[x+2][y+2]&&v[x+1][y+1])||(v[x-1][y]&&v[x+1][y])||(v[x][y-1]&&v[x][y+1])||(v[x-1][y-1]&&v[x+1][y+1])||(v[x-1][y+1]&&v[x+1][y-1])) return true; return false;}int main(){ memset(v,0,sizeof(v)); for(int i=2;i<=5;i++) { scanf("%s",map[i]+2); for(int j=2;j<=5;j++) { if(map[i][j]=='x') v[i][j]=1; } } bool Q=false; for(int i=2;i<=5;i++) { for(int j=2;j<=5;j++) { if(map[i][j]=='.'&&search(i,j)) { Q=true; break; } } if(Q) break; } if(Q) cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0;}
- 【Codeforces 754 B Ilya and tic-tac-toe game】
- 【codeforces 754B】 Ilya and tic-tac-toe game
- codeforces 754 B Ilya and tic-tac-toe game
- CodeForces 754B Ilya and tic-tac-toe game
- B. Ilya and tic-tac-toe game
- Cdoeforces 754 B - Ilya and tic-tac-toe game
- 754B Ilya and tic-tac-toe game
- 754B. Ilya and tic-tac-toe game
- Codeforces-754B-Ilya and tic-tac-toe game(简单模拟判断)
- Codeforces Round #390(Div. 2)B. Ilya and tic-tac-toe game【模拟】
- 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 Round #390 (Div. 2)B Ilya and tic-tac-toe game
- Codeforces #390 (Div. 2) B. Ilya and tic-tac-toe game ( DFS
- 2017寒假集训-小题训练1:F - Ilya and tic-tac-toe game
- 001 tic-tac-toe game
- [Codeforces]C. Tic-tac-toe
- uva 11623 - Tic Tac Toe(game)
- LeetCode 2 Add Two Numbers
- 四年之后
- Java 循环结构
- zk简介
- 如何搭建一个网站
- codeforces 754 B Ilya and tic-tac-toe game
- 教你怎样操作编辑PDF文件,修改PDF上的文字
- 截图,截屏
- android shape的使用
- 面试题之jsp九大内置对象
- 网络请求content-type类型
- jmeter实现返回json串的断言
- C++ 的 __LINE__和 __FUNCTION__
- Git常用命令总结