标签:des style blog http color os io strong for
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.
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.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
3
xxo
xox
oxx
YES
4
xxxo
xoxo
oxox
xxxx
NO
解题:暴力枚举即可。
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> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 110; 18 int n; 19 char mp[maxn][maxn]; 20 const int dir[4][2] = {0,-1,0,1,-1,0,1,0}; 21 int main() { 22 int ans; 23 bool flag; 24 while(~scanf("%d",&n)){ 25 getchar(); 26 memset(mp,‘x‘,sizeof(mp)); 27 for(int i = 1; i <= n; i++){ 28 for(int j = 1; j <= n; j++) 29 mp[i][j] = getchar(); 30 getchar(); 31 } 32 flag = true; 33 for(int i = 1; i <= n; i++){ 34 for(int j = 1; j <= n; j++){ 35 ans = 0; 36 for(int k = 0; k < 4; k++){ 37 int x = i+dir[k][0]; 38 int y = j+dir[k][1]; 39 if(mp[x][y] == ‘o‘) ans++; 40 } 41 if(ans&1) {flag = false;break;} 42 } 43 } 44 flag?puts("YES"):puts("NO"); 45 } 46 return 0; 47 }
Codeforces 263A. Appleman and Easy Task
标签:des style blog http color os io strong for
原文地址:http://www.cnblogs.com/crackpotisback/p/3938673.html