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

3xxoxoxoxx

output

YES

input

4xxxoxoxooxoxxxxx

output

NO

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

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

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5
 6 using namespace std;
 7 const int max_size = 105;
 8
 9 int d1[] = {-1, 0, 0, 1};
10 int d2[] = {0, -1, 1, 0};
11
12 bool check(int x, int y, int n)
13 {
14     if(x >= 0 && y >= 0 && x < n && y < n)
15         return true;
16     return false;
17 }
18
19 int main()
20 {
21     int n;
22     int graph[max_size][max_size];
23
24     while(scanf("%d%*c", &n) != EOF)
25     {
26         for(int i = 0; i < n; i++)
27         {
28             for(int j = 0; j < n; j++)
29             {
30                 char a = getchar();
31                 if(a == ‘o‘)
32                     graph[i][j] = 1;
33                 else
34                     graph[i][j] = 0;
35             }
36             getchar();
37         }
38
39         int tag = false;
40         for(int i = 0; i < n; i++)
41         {
42             for(int j = 0; j < n; j++)
43             {
44                 int ans = 0;
45                 int x, y;
46                 for(int k = 0; k < 4; k ++)
47                 {
48                     x = i + d1[k];
49                     y = j + d2[k];
50                     if(check(x, y, n))
51                     {
52                         if(graph[x][y] == 1)
53                             ans++;
54                     }
55                 }
56                 if(ans % 2 != 0)
57                 {
58                     printf("NO\n");
59                     tag = true;
60                     break;
61                 }
62             }
63             if(tag == true)
64                 break;
65         }
66         if(tag == false)
67             printf("YES\n");
68     }
69     return 0;
70 }

时间: 2024-10-11 17:42:01

CodeForces462 A. Appleman and Easy Task的相关文章

Codeforces 263A. 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

哈理工2015暑假训练赛BNU16488 Easy Task(简单题)

A - Easy Task Time Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu SubmitStatusPracticeZOJ 2969 Description Calculating the derivation of a polynomial is an easy task. Given a function f(x) , we use (f(x))' to denote its derivatio

HDU-1076-An Easy Task(Debian下水题测试.....)

An Easy Task Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17062    Accepted Submission(s): 10902 Problem Description Ignatius was born in a leap year, so he want to know when he could hold h

[ACM] ZOJ 3844 Easy Task (模拟+哈希)

Easy Task Time Limit: 2 Seconds      Memory Limit: 65536 KB You are given n integers. Your task is very easy. You should find the maximum integer a and the minimum integer b among these n integers. And then you should replace both a and bwith a-b. Yo

杭电OJ(HDU)-ACMSteps-Chapter Two-《An Easy Task》《Buildings》《decimal system》《Vowel Counting》

http://acm.hdu.edu.cn/game/entry/problem/list.php?chapterid=1§ionid=2 1.2.5 #include<stdio.h> /* 题意:找闰年. if((i%4==0 && i%100!=0) || i%400==0)count++; 3 2005 25 1855 12 2004 10000 2108 1904 43236 */ int main() { int t,y,n; int i,count=0; whil

ZOJ 2969: Easy Task

ZOJ 2969: Easy Task 1 ///@date 2017-02-07 2 ///@author Sycamore, ZJNU 3 #include <iostream> 4 using namespace std; 5 int c[1001]; 6 int main() 7 { 8 int T; 9 cin >> T; 10 while (T--) 11 { 12 int N; 13 cin >> N; 14 for (int i = N; i >=

HDU-------An Easy Task

An Easy Task Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4088 Accepted Submission(s): 2327   Problem Description Ignatius was born in a leap year, so he want to know when he could hold his bir

2016 省热身赛 Easy Task

Easy Task Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description You are given n integers. Your task is very easy. You should find the maximum integer a and the minimum integer b among these nintegers. And then you sho

An Easy Task(简箪题)

B. An Easy Task Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main Submit Status PID: 35999 Font Size:  +   - You are given an easy task by your supervisor -- to find the best va