现在的位置: 首页 > 综合 > 正文

Codeforces Round #263 (Div. 2)-C. Appleman and Toastman

2018年05月02日 ⁄ 综合 ⁄ 共 1298字 ⁄ 字号 评论关闭

A. Appleman and Easy Task
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?

Given a n × n checkerboard.
Each cell of the board has either character 'x', or character 'o'.
Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.

Input

The first line contains an integer n (1 ≤ n ≤ 100).
Then n lines follow containing the description of the checkerboard. Each of them contains n characters
(either 'x' or 'o') without spaces.

Output

Print "YES" or "NO"
(without the quotes) depending on the answer to the problem.

Sample test(s)
input
3
xxo
xox
oxx
output
YES
input
4
xxxo
xoxo
oxox
xxxx
output
NO
//题意:给你一个NxN的棋盘,问'x'相邻的‘o’都是是偶数个就输出YES否则输出NO
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
const int Max=201;
char Map[Max][Max];
using namespace std;
int main()
{
    int i,j,n,m,num;
    while(cin>>n)
    {
        m=0;
        num=0;
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                cin>>Map[i][j];
            }
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                num=0;
                if(i>1&&Map[i-1][j]=='o')
                    num++;
                if(i<n&&Map[i+1][j]=='o')
                    num++;
                if(j>1&&Map[i][j-1]=='o')
                    num++;
                if(j<n&&Map[i][j+1]=='o')
                    num++;
                if(num&1)
                {
                    m=1;
                    break;
                }
            }
            if(m==1)
                break;
        }
        if(!m)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

抱歉!评论已关闭.