Appleman and Easy Task-cf

来源:互联网 发布:逆战神枪手源码 编辑:程序博客网 时间:2024/05/17 07:01



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.

Sample test(s)
input
3xxoxoxoxx
output
YES
input
4xxxoxoxooxoxxxxx
output
NO
我题目没注意到是不管x,还是o,都找寻周围是否有偶数个o



#include<iostream>using namespace std;char a[200][200];int vis[200][200];int n;int dfs(int i, int j){int num = 0;if (a[i - 1][j] == 'o'&&i>0 && i <= n&&j <= n&&j>0)num++;if (a[i][j - 1] == 'o'&&i>0 && i <= n&&j <= n&&j>0)num++;if (a[i][j + 1] == 'o'&&i>0 && i <= n&&j <= n&&j>0)num++;if (a[i + 1][j] == 'o'&&i>0 && i <= n&&j <= n&&j>0)num++;return num;}int main(){//int n;cin >> n;for (int i = 1; i <= n; i++){for (int j = 1; j <= n; j++){cin >> a[i][j];}}int x = 0, flag = 0;for (int i = 1; i <= n; i++){for (int j = 1; j <= n; j++){x = dfs(i, j);if (x % 2 != 0){flag = 1;break;}}if (flag)break;}if (flag)cout << "NO" << endl;elsecout << "YES" << endl;}




0 0