A. Appleman and Easy TaskTime limit per test 1 secondmemory limit per test megabytes input
Standard Input
Output
Standard Output
Toastman came up and a very easy task. He gives it to Appleman, but Appleman doesn ' t know what to solve it. Can you help him?
Given a n x n Checkerboard. Each cell of the board has either character 'X ', or character 'o '. Is it true this each cell of the board have even number of adjacent cells with 'o '? Both 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
Problem solving: Brute force enumeration.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <climits>7#include <vector>8#include <queue>9#include <cstdlib>Ten#include <string> One#include <Set> A#include <stack> - #defineLL Long Long - #definePII pair<int,int> the #defineINF 0x3f3f3f3f - using namespacestd; - Const intMAXN = the; - intN; + CharMP[MAXN][MAXN]; - Const intdir[4][2] = {0,-1,0,1,-1,0,1,0}; + intMain () { A intans; at BOOLFlag; - while(~SCANF ("%d",&N)) { - GetChar (); -Memset (MP,'x',sizeof(MP)); - for(inti =1; I <= N; i++){ - for(intj =1; J <= N; J + +) inMP[I][J] =GetChar (); - GetChar (); to } +Flag =true; - for(inti =1; I <= N; i++){ the for(intj =1; J <= N; J + +){ *Ans =0; $ for(intK =0; K <4; k++){Panax Notoginseng intx = i+dir[k][0]; - inty = j+dir[k][1]; the if(Mp[x][y] = ='o') ans++; + } A if(ans&1) {flag =false; Break;} the } + } -Flag?puts ("YES"):p UTS ("NO"); $ } $ return 0; -}
View Code
Codeforces 263A. Appleman and Easy Task