CodeForces462 A. Appleman and Easy Task

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
3
xxo
xox
oxx
output
YES
input
4
xxxo
xoxo
oxox
xxxx
output
NO

英语真的是差啊,没办法,没理解,好好学英语,这学期过CET4,加油!

遍历搞一下这道题就过了。

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std;
const int max_size = ; int d1[] = {-, , , };
int d2[] = {, -, , }; bool check(int x, int y, int n)
{
if(x >= && y >= && x < n && y < n)
return true;
return false;
} int main()
{
int n;
int graph[max_size][max_size]; while(scanf("%d%*c", &n) != EOF)
{
for(int i = ; i < n; i++)
{
for(int j = ; j < n; j++)
{
char a = getchar();
if(a == 'o')
graph[i][j] = ;
else
graph[i][j] = ;
}
getchar();
} int tag = false;
for(int i = ; i < n; i++)
{
for(int j = ; j < n; j++)
{
int ans = ;
int x, y;
for(int k = ; k < ; k ++)
{
x = i + d1[k];
y = j + d2[k];
if(check(x, y, n))
{
if(graph[x][y] == )
ans++;
}
}
if(ans % != )
{
printf("NO\n");
tag = true;
break;
}
}
if(tag == true)
break;
}
if(tag == false)
printf("YES\n");
}
return ;
}
上一篇:pip install psycopg2出现python setup.py egg_info failed with error code 1 in /tmp/pip-build-YtLeN3/psycopg2错误处理


下一篇:链接中 href='#' 和 href='###' 的区别以及优缺点