codeforces 462A Appleman and Easy Task

来源:互联网 发布:kegg数据库是做什么 编辑:程序博客网 时间:2024/06/04 19:30

点击打开链接

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.

Examples
input
3xxoxoxoxx
output
YES
input
4xxxoxoxooxoxxxxx
output
NO


水题,直接暴力。

#include<bits/stdc++.h>using namespace std;int main(){    int n;    scanf("%d",&n);    getchar();    char a[110][110];    for(int i=1;i<=n;i++)    {    for(int j=1;j<=n;j++)    {    scanf("%c",&a[i][j]);    }    getchar();    }    bool flag=false;    for(int i=1;i<=n;i++)    {    for(int j=1;j<=n;j++)    {    if(!flag)    {    int s=0;    if(a[i-1][j]=='o'&&i-1>0&&i-1<=n&&j>0&&j<=n)    s++;    if(a[i+1][j]=='o'&&i+1>0&&i+1<=n&&j>0&&j<=n)    s++;    if(a[i][j-1]=='o'&&i>0&&i<=n&&j-1>0&&j-1<=n)    s++;    if(a[i][j+1]=='o'&&i>0&&i<=n&&j+1>0&&j+1<=n)    s++;    if(s%2==1)    {    flag=true;    break;    }    }    }    if(flag)    break;    }    if(flag)    cout<<"NO"<<endl;    else    cout<<"YES"<<endl;    return 0;}


阅读全文
0 0
原创粉丝点击