CF #263 (Div. 2) A

来源:互联网 发布:mac彻底删除音乐创作 编辑:程序博客网 时间:2024/05/18 01:18

A. Appleman and Easy Task
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
题目链接:http://codeforces.com/problemset/problem/462/A

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 ncharacters (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
3xxoxoxoxx
output
YES
input
4xxxoxoxooxoxxxxx
output
NO




解题思路:

        题意是求每个位置周围的'o'是否为偶数,如果不是偶数,输出NO,否则输出YES.

        每个位置如果是x则存0,是o则存1。两层循环遍历每个位置,把四个位置做和(下标不越界的情况下),如果最后

和是奇数,直接跳出循环,输出NO;否则继续往下遍历。





完整代码:

#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;char maps[1111][1111];int n;char str[100001];int g[1111][1111];int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif    while(~scanf("%d",&n))    {        memset(g , 0 , sizeof(g));        for(int i = 0 ; i < n ; i ++)        {            scanf("%s",str);            for(int j = 0 ; j < n ; j ++)            {                maps[i][j] = str[j];                if(maps[i][j] == 'o')                    g[i][j] = 1;            }        }        int flag = 0;        int sum;        for(int i = 0 ; i < n ; i ++)        {            for(int j = 0 ; j < n ; j ++)            {                sum = 0;                if(i - 1 >= 0)                    sum += g[i-1][j];                if(i + 1 < n)                    sum += g[i+1][j];                if(j + 1 < n)                    sum += g[i][j+1];                if(j - 1 >= 0)                    sum += g[i][j-1];                if(sum % 2 != 0 )                {                    flag = 1;                    break;                }            }            if(flag)                break;        }        if(!flag)            printf("YES\n");        else            printf("NO\n");    }}



0 0