zoukankan      html  css  js  c++  java
  • 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 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

    解题:暴力枚举即可。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <climits>
     7 #include <vector>
     8 #include <queue>
     9 #include <cstdlib>
    10 #include <string>
    11 #include <set>
    12 #include <stack>
    13 #define LL long long
    14 #define pii pair<int,int>
    15 #define INF 0x3f3f3f3f
    16 using namespace std;
    17 const int maxn = 110;
    18 int n;
    19 char mp[maxn][maxn];
    20 const int dir[4][2] = {0,-1,0,1,-1,0,1,0};
    21 int main() {
    22     int ans;
    23     bool flag;
    24     while(~scanf("%d",&n)){
    25         getchar();
    26         memset(mp,'x',sizeof(mp));
    27         for(int i = 1; i <= n; i++){
    28             for(int j = 1; j <= n; j++)
    29                 mp[i][j] = getchar();
    30             getchar();
    31         }
    32         flag = true;
    33         for(int i = 1; i <= n; i++){
    34             for(int j = 1; j <= n; j++){
    35                 ans = 0;
    36                 for(int k = 0; k < 4; k++){
    37                     int x = i+dir[k][0];
    38                     int y = j+dir[k][1];
    39                     if(mp[x][y] == 'o') ans++;
    40                 }
    41                 if(ans&1) {flag = false;break;}
    42             }
    43         }
    44         flag?puts("YES"):puts("NO");
    45     }
    46     return 0;
    47 }
    View Code
  • 相关阅读:
    HTML入门(一)
    WEB攻击手段及防御第2篇-SQL注入
    公司来了个新同事不会用 Lombok,还说我代码有问题!
    最流行的 RESTful API 要怎么设计?
    Spring Boot & Restful API 构建实战!
    分布式事务不理解?一次给你讲清楚!
    带着问题学 Kubernetes 架构!
    Linux 与 Unix 到底有啥区别和联系?
    Java虚拟机最多支持多少个线程?
    常用的 Git 命令,给你准备好了!
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/3938673.html
Copyright © 2011-2022 走看看