Appleman and Easy Task
2016-01-06 15:01
429 查看
Description
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 Input
Input
Output
Input
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 Input
Input
3 xxo xox oxx
Output
YES
Input
4 xxxo xoxo oxox xxxx
Output
NO
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; char mp[110][110]; int n; int main(){ while(cin>>n){ int ok=1; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++) cin>>mp[i][j]; } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ int cnt=0; if(mp[i+1][j]=='o') cnt++; if(mp[i-1][j]=='o') cnt++; if(mp[i][j-1]=='o') cnt++; if(mp[i][j+1]=='o') cnt++; if(cnt&1){//取cnt的最左边一位.例如cnt是0011,cnt&1得到0001,如果cnt是0110,cnt&1得到0000,即判断奇偶,效率比cnt%2高 ok=0; break; } } } if(ok) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
相关文章推荐
- objective c to pas
- iOS-读写plist文件
- swift 获取idfa
- iOS新特性
- Android 高仿 频道管理----网易、今日头条、腾讯视频 (可以拖动的GridView)附源码DEMO
- Android开发中的屏幕适配问题
- Swift语法之 ---- ?和!区别
- Android应用开发中的风格和主题(style,themes)
- Android中Application类用法
- ubuntu 14.04 搭建Android 源码(AOSP)编译环境
- Android权限机制
- android学习日记(三):Fragment的实战上
- android按键事件和触屏事件(三)-带你从源码的角度彻底理解
- lambda 表达式
- Android KITKAT 以上实现沉浸式状态栏
- android按键事件和触屏事件(二)-带你从源码的角度彻底理解
- Android开发常用的adb命令整理
- ios微信支付调起微信只显示一个确定按钮
- iOS开发-工厂模式
- iOS笔记链接