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

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

Output

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

Example
Input
xx...oo.x...oox.
Output
YES
Input
x.oxox..x.o.oo.x
Output
NO
Input
x..x..ooo...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.

题目大意:

类似于五子棋的问题


题目分析:

暴力模拟,这里我把数组开成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;}

0 0
原创粉丝点击