Codeforces round #263 (Div. 2) proa

Source: Internet
Author: User
Question: 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?

GivenN? ×?NCheckerboard. 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 integerN(1? ≤?N? ≤? 100). ThenNLines follow containing the description of the checkerboard. Each of them containsNCharacters (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
Meaning analysis: determines the number where each position is adjacent to O. If all the numbers are even, yes and no are returned. Simple question simulation. Orz
Code:
#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>#include <string>#include <iostream>using namespace std;char a[105][105];int main(){    int n;    char c;    int flag;    cin >> n;    memset(a, 0, sizeof(a));    for(int i=1; i<=n; i++)        for(int j=1; j<=n; j++)        {            cin >> c;            if (c == 'o')                a[i][j] = 1;        }    flag = 1;    for(int i=1; i<=n; i++)        for(int j=1; j<=n; j++)        {            int cnt = 0;            if (a[i-1][j])                ++cnt;            if (a[i+1][j])                ++cnt;            if (a[i][j-1])                ++cnt;            if (a[i][j+1])                ++cnt;            if (cnt & 1)            {                flag = false;                break;            }        }    if (flag)        cout << "YES" << endl;    else        cout << "NO" << endl;    return 0;}


Codeforces round #263 (Div. 2) proa

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.