A. Appleman and Easy Task
来源:互联网 发布:java并发编程实战 pdf 编辑:程序博客网 时间:2024/06/06 10:56
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.
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.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
3xxoxoxoxx
YES
4xxxoxoxooxoxxxxx
NO
解题说明:此题是一道图形题,要求判断棋盘中的每个单元是否都有偶数个“o”相邻,最简单的办法是依次遍历,如果遇到一个不满足的就跳出循环打印NO。
#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<cstdlib>#include<cstring>using namespace std;int main(){int n,i,j,count,flag=0;char a[102][102];scanf("%d",&n);for(i=0;i<n;i++){scanf("%s",&a[i]);}for(i=0;i<n;i++){for(j=0;j<n;j++){count=0;if((i-1)>=0&&a[i-1][j]=='o'){count++;}if((j-1)>=0&&a[i][j-1]=='o'){count++;}if((i+1)<n&&a[i+1][j]=='o'){count++;}if((j+1)<n&&a[i][j+1]=='o'){count++;}if(count%2!=0){flag=1;break;}}if(flag==1){break;}}if(flag==1){printf("NO\n");}else{printf("YES\n");}return 0;}
- A. Appleman and Easy Task
- A. Appleman and Easy Task 8-26
- 462A - Appleman and Easy Task
- 【CODEFORCES】 A. Appleman and Easy Task
- codeforces 462A Appleman and Easy Task
- Appleman and Easy Task
- Appleman and Easy Task-cf
- Codeforces Round #263 (Div. 2)A. Appleman and Easy Task
- Codeforces Round #263 (Div. 2)A. Appleman and Easy Task
- Codeforces Round #263 (div2) A. Appleman and Easy Task
- Codeforces 462A Appleman and Easy Task(水题)
- A. Appleman and Easy Task( brute force implementation)
- Codeforces Round #263 (Div. 2) A.Appleman and Easy Task(坑)
- 【Codeforces Round 263 (Div 2)A】【水题 认真读题】Appleman and Easy Task 每个点的相邻o是否都为偶数
- A. Appleman and Toastman
- 461A - Appleman and Toastman
- Codeforces-461A Appleman and Toastman
- Appleman and Toastman - CodeForces 461 A 水题
- 无线自动卷帘门智能无噪音
- 10010
- windows下MySQL出现2003错误解决办法
- MFC CPropertySheet 多页面切换 实例 .
- Automatic Poetry
- A. Appleman and Easy Task
- 转载和积累系列 - CentOS 常用小技巧集合
- java多线程:线程的调度-合并
- 13-14,与你有个长相守约定
- c语言知识点
- 优秀程序员与糟糕程序员的区别,which you want to be!Fight!
- Web——前端开发技术包括三个要素
- 觉得更加客观号码上的符号史蒂夫
- 常见的概率相关面试题(1)