CodeForces462 A. Appleman and Easy Task

來源:互聯網
上載者:User

標籤:

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?

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,加油!

遍曆搞一下這道題就過了。

 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                 else34                     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 }
View Code

 

CodeForces462 A. Appleman and Easy Task

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.