CodeForces 825B Five-In-a-Row

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

NO

题目大意:5-in-a-row game就是五子棋啦。两个人在一个10×10的棋盘上下五子棋,Alice画×,Bob画○,给出一张他们已经下了的图,现在轮到Alice下了,问Alice是否会赢。

大致思路:简单模拟遍历棋盘中的每一能走的点,如果这个点所处的行,列或者对角线存在5个连续的×,那么Alice会赢。例如所在的行无法满足要求,那就判断列,以此类推。所在的点如果找不到符合要求的,就换下一个点。详见代码。
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    char a[10][10];
    int i,j,k,l,m,n,flag,cou;
    while(scanf("%s",a[0])==1)
    {
        flag=0;
        for(i=1;i<10;i++)
            scanf("%s",a[i]);
        for(i=0;i<10;i++)
        {
            for(j=0;j<10;j++)
            {
                if(a[i][j]==‘.‘)
                {
                    cou=0;//判断开始前都要将计数器归0
                    for(k=j-1;k>=0&&a[i][k]==‘X‘;k--)//行变
                        cou++;
                    for(k=j+1;k<10&&a[i][k]==‘X‘;k++)
                        cou++;
                    if(cou>=4)
                    {
                        flag=1;
                        cout<<"Yes"<<endl;
                        break;
                    }
                    cou=0;
                    for(l=i-1;l>=0&&a[l][j]==‘X‘;l--)//列变
                        cou++;
                    for(l=i+1;l<10&&a[l][j]==‘X‘;l++)
                        cou++;
                    if(cou>=4)
                    {
                        flag=1;
                        cout<<"Yes"<<endl;
                        break;
                    }
                    cou=0;
                    for(m=i-1,n=j-1;m>=0&&n>=0&&a[m][n]==‘X‘;m--,n--)//"\"方向对角线
                        cou++;
                    for(m=i+1,n=j+1;m<10&&n<10&&a[m][n]==‘X‘;m++,n++)
                        cou++;
                    if(cou>=4)
                    {
                        flag=1;
                        cout<<"Yes"<<endl;
                        break;
                    }
                    cou=0;
                    for(m=i-1,n=j+1;m>=0&&n<10&&a[m][n]==‘X‘;m--,n++)//"/"方向对角线
                        cou++;
                    for(m=i+1,n=j-1;m<10&&n>=0&&a[m][n]==‘X‘;m++,n--)
                        cou++;
                    if(cou>=4)
                    {
                        flag=1;
                        cout<<"Yes"<<endl;
                        break;
                    }
                }
            }
            if(flag)
                break;
        }
        if(!flag)
            cout<<"No"<<endl;
    }
    return 0;
}
时间: 2024-08-08 15:04:07

CodeForces 825B Five-In-a-Row的相关文章

CodeForces 825B(模拟&amp;贪心_D题)解题报告

题目链接:http://codeforces.com/problemset/problem/825/B -------------------------------------------------------------------------------- 题意:五子棋,在输入条件下,能否在当前局面获胜. 思路:很明显的是,当我们下五子棋时,我们每步都是进行一次搜索,观察能否连接成为5个.同理,利用计算机也可以向各个方向进行搜索.好在本题只是10X10的棋面,直接对每个点进行4个方向(水

CodeForces - 402B Trees in a Row (暴力)

题意:给定n个数,要求修改其中最少的数,使得这n个数满足ai + 1 - ai = k. 分析: 暴力,1000*1000. 1.这n个数,就是一个首项为a1,公差为k的等差数列.k已知,如果确定了a1,就能确定整个数列. 2.1 ≤ ai ≤ 1000,因此,可以从1~1000中枚举a1,将形成的数列与给定的数列比较,统计两数列对应下标中不同数字的个数. 3.不同数字的个数最少的那个数列就是最终要修改成的数列,然后输出对应下标的那个数的变化值即可. #include<cstdio> #inc

Codeforces 620C EDU C.Pearls in a Row ( set + greed )

C. Pearls in a Row There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it cont

Pearls in a Row CodeForces 620C 水题

题目:http://codeforces.com/problemset/problem/620/C 文章末有一些测试数据仅供参考 题目大意:就是给你一个数字串,然后将分成几个部分,要求每个部分中必须有一对儿相等的数字,每个数字都属于某个部分,输出划分的部分数量以及对应区间. 很简单一道题,输入的数据都不用存的,输入一个检测一个就好了,用map打标记,用容器存一下要输出的区间端点值,最后挨个儿输出就好了 代码如下: #include<iostream> #include<map> #

Codeforces Round #484 (Div. 2) A. Row

A. Row time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You're given a row with nn chairs. We call a seating of people "maximal" if the two following conditions hold: There are no neigh

CodeForces 347A Difference Row (水题)

题意:给定 n 个数,让你找出一个排列满足每个数相邻作差之和最大,并且要求字典序最小. 析:这个表达式很简单,就是把重新组合一下,就成了x1-xn,那么很简单,x1是最大的,xn是最小的,中间排序就好. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <cstring> using namespace std;

CodeForces 510 A. Fox And Snake(模拟啊 )

题目链接:http://codeforces.com/problemset/problem/510/A Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a n by m

CodeForces 1B. Spreadsheets(模拟)

题目链接:http://codeforces.com/problemset/problem/1/B B. Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard input output standard output In the popular spreadsheets systems (for example, in Excel) the following

Codeforces Round #256 (Div. 2) C. Painting Fence(分治贪心)

题目链接:http://codeforces.com/problemset/problem/448/C ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943