Five-In-a-Row CodeForces

来源:互联网 发布:漫画人软件 编辑:程序博客网 时间:2024/06/06 17:15

Five-In-a-Row CodeForces - 825B

 

Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.

In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately.

Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.

Input

You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell.

It is guaranteed that in the current arrangement nobody has still won.

Output

Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.

Example
Input
XX.XX..........OOOO.................................................................................
Output
YES
Input
XXOXX.....OO.O......................................................................................
Output
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char mp[12][12];int flag=0,sum=0;void dfs(int x,int y){    int i,j,t;    for(i=x,j=y-1; j>=0; j--) //向左    {        if(mp[i][j]!='X')break;        else sum++;    }    for(i=x,j=y+1; j<10; j++) //向右    {        if(mp[i][j]!='X')break;        else sum++;    }    if(sum>=4)    {        flag=1;        return ;    }    else sum=0;    //////////////////////////////////////    for(i=x-1,j=y; i>=0; i--) //向上    {        if(mp[i][j]!='X')break;        else sum++;    }    for(i=x+1,j=y; i<10; i++) //向下    {        if(mp[i][j]!='X')break;        else sum++;    }    if(sum>=4)    {        flag=1;        return ;    }    else sum=0;    //////////////////////////////////////////    for(i=x,j=y,t=1;t<=4; t++) //向右上    {        if(i-t<0||j+t>=10||mp[i-t][j+t]!='X')            break;        else sum++;    }    for(i=x,j=y,t=1;t<=4; t++) //向左下    {        if(i+t<0||j-t>=10||mp[i+t][j-t]!='X')            break;        else sum++;    }    if(sum>=4)    {        flag=1;        return ;    }    else sum=0;    ///////////////////////////////////////    for(i=x,j=y,t=1;t<=4; t++) //向右上    {        if(i-t<0||j-t>=10||mp[i-t][j-t]!='X')            break;        else sum++;    }    for(i=x,j=y,t=1;t<=4; t++) //向右上    {        if(i+t<0||j+t>=10||mp[i+t][j+t]!='X')            break;        else sum++;    }    if(sum>=4)    {        flag=1;        return ;    }    else sum=0;}int main(){    while(gets(mp[0]))    {        for(int i=1; i<10; i++)            scanf("%s",mp[i]);        flag=0;        sum=0;        for(int i=0; i<10; i++)        {            for(int j=0; j<10; j++)            {                if(mp[i][j]=='.')                {                    dfs(i,j);                    if(flag)                        break;                }            }            if(flag)                break;        }        if(flag)            printf("YES\n");        else printf("NO\n");        getchar();    }}

NO
题意:10*10的棋盘内,如果加上一个‘X’后连续在水平,垂直,对角方向上出现5个以上的‘X’时输出YES,否则的话输出NO
思想及方法:向上向下,向左向右,向左上向右下,向左下向右上,分别找四个以上的话break;输出YES,找不到的话输出NO。

原创粉丝点击