zoukankan      html  css  js  c++  java
  • Codeforces Round #263 (Div. 2) A. Appleman and Easy Task【地图型搜索/判断一个点四周‘o’的个数的奇偶】

    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.

    Examples
    input
    3
    xxo
    xox
    oxx
    output
    YES
    input
    4
    xxxo
    xoxo
    oxox
    xxxx
    output
    NO

    【题意】:Two cells of the board are adjacent if they share a side. 指的是四周

    【Code】:
    #include <bits/stdc++.h>
    using namespace std;
    const int N =110;
    int cnt,n;
    
    char a[N][N];
    int dir[][2]={ {-1,0},{0,-1},{1,0},{0,1} };
    
    int dfs(int x,int y)
    {
        for(int i=0;i<4;i++)
        {
            int dx=x+dir[i][0];
            int dy=y+dir[i][1];
    
            if(dx>=0&&dy>=0&&dx<n&&dy<n)
            {
                if(a[dx][dy]=='o')
                    cnt++;
            }
        }
        return cnt;
    }
    bool check()
    {
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(dfs(i,j)&1)
                    return false;
            }
        }
        return true;
    }
    int main()
    {
    	cin>>n;
    	for(int i=0;i<n;i++)
            scanf("%s",a[i]);
    
        printf("%s
    ",check()?"YES":"NO");
    	return 0;
    }
    

      

  • 相关阅读:
    opencv图像直方图均衡化及其原理
    转 让FPGA替代GPU的6大顾虑,你确定不看看吗?
    算法工程师到底在干嘛
    转 经典分类网络Googlenet
    darknet是如何对数据集做预处理的
    目标检测评价指标mAP 精准率和召回率
    opencv代码片段合集
    GAN简介
    【登录测试】登录模块的测试点
    【Jmeter自学】Jmeter里的指标
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7995277.html
Copyright © 2011-2022 走看看