Codeforces Round #263 (Div. 2) A.Appleman and Easy Task(坑)

本文深入解析并提供了解决复杂矩阵问题的方法,即检查每个位置的四面相邻元素中'o'的数量是否为偶数。通过实例演示,帮助读者理解并解决类似Appleman遇到的EasyTask。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


题解:

个人感觉昨晚上的CF的A题坑到要死了,正确题意是若所给矩阵中的每一个位置四面相邻的共有偶数个'o'的话,就是YES,否则是NO,但真心无力吐槽题中的一句话Two cells of the board are adjacent if they share a side.什么是共用一条边。。。自然而然想到了同行或同列,但是WA了两个小时,今天看题解才知道,这句话就是个摆设,直接考虑边界判断str[i-1][j] str[i+1][j] str[i][j-1] str[i][j+1] 就好了。。。Orz。。。。。


题目链接:http://codeforces.com/problemset/problem/462/A


代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

int main(){
    int n;
    char str[110][110];
    scanf("%d",&n);
    getchar();
    for(int i=0;i<n;i++){
        gets(str[i]);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int cnt=0;
            if(i!=0&&str[i-1][j]=='o') cnt++;
            if(i!=n-1&&str[i+1][j]=='o') cnt++;
            if(j!=0&&str[i][j-1]=='o') cnt++;
            if(j!=n-1&&str[i][j+1]=='o') cnt++;
            if(cnt%2==1) ans=1;
        }
    }
    if(ans) printf("NO\n");
    else printf("YES\n");
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值