Question: A. appleman and easy tasktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard 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?
GivenN? ×?NCheckerboard. 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 integerN(1? ≤?N? ≤? 100). ThenNLines follow containing the description of the checkerboard. Each of them containsNCharacters (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
Meaning analysis: determines the number where each position is adjacent to O. If all the numbers are even, yes and no are returned. Simple question simulation. Orz
Code:
#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>#include <string>#include <iostream>using namespace std;char a[105][105];int main(){ int n; char c; int flag; cin >> n; memset(a, 0, sizeof(a)); for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) { cin >> c; if (c == 'o') a[i][j] = 1; } flag = 1; for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) { int cnt = 0; if (a[i-1][j]) ++cnt; if (a[i+1][j]) ++cnt; if (a[i][j-1]) ++cnt; if (a[i][j+1]) ++cnt; if (cnt & 1) { flag = false; break; } } if (flag) cout << "YES" << endl; else cout << "NO" << endl; return 0;}
Codeforces round #263 (Div. 2) proa