您的位置:首页 > 其它

Codeforces Round #390(Div. 2)B. Ilya and tic-tac-toe game【模拟】

2017-01-07 01:21 477 查看
B. Ilya and tic-tac-toe game

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

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 gets
three of his signs in a row next to each other (horizontal, vertical or diagonal).

Input
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 letter
x), or 'o' (lowercase English letter
o). 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.

Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.

Examples

Input
xx..
.oo.
x...
oox.


Output
YES


Input
x.ox
ox..
x.o.
oo.x


Output
NO


Input
x..x
..oo
o...
x.xo


Output
YES


Input
o.x.
o...
.x..
ooxx


Output
NO


Note
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.

题目大意:

给你一个初始的图,问你能否在一步操作中x取得胜利

思路:

暴力模拟即可。

Ac代码:

#include<stdio.h>
#include<string.h>
using namespace std;
char a[10][10];
int fx[8]={1,-1,0,0,1,-1,1,-1};
int fy[8]={0,0,1,-1,1,-1,-1,1};
int judge()
{
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(a[i][j]=='x')
{
for(int z=0;z<8;z++)
{
int flag=0;
for(int k=1;k<=2;k++)
{
int xx=i+fx[z]*k;
int yy=j+fy[z]*k;
if(xx>=0&&xx<4&&yy>=0&&yy<4)
{
if(a[xx][yy]=='x')continue;
else flag=1;
}
else flag=1;
}
if(flag==0)return 1;
}
}
}
}
return 0;
}
int main()
{
memset(a,'.',sizeof(a));
for(int i=0;i<4;i++)
{
scanf("%s",a[i]);
}
int flag=0;
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(a[i][j]=='.')
{
a[i][j]='x';
int tmp=judge();
a[i][j]='.';
if(tmp==1)flag=1;
}
}
}
if(flag==1)printf("YES\n");
else printf("NO\n");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Codeforces#390Div. 2