CF #263 (Div. 2) A
来源:互联网 发布:mac彻底删除音乐创作 编辑:程序博客网 时间:2024/05/18 01:18
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 ncharacters (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,否则输出YES.
每个位置如果是x则存0,是o则存1。两层循环遍历每个位置,把四个位置做和(下标不越界的情况下),如果最后
和是奇数,直接跳出循环,输出NO;否则继续往下遍历。
完整代码:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;char maps[1111][1111];int n;char str[100001];int g[1111][1111];int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif while(~scanf("%d",&n)) { memset(g , 0 , sizeof(g)); for(int i = 0 ; i < n ; i ++) { scanf("%s",str); for(int j = 0 ; j < n ; j ++) { maps[i][j] = str[j]; if(maps[i][j] == 'o') g[i][j] = 1; } } int flag = 0; int sum; for(int i = 0 ; i < n ; i ++) { for(int j = 0 ; j < n ; j ++) { sum = 0; if(i - 1 >= 0) sum += g[i-1][j]; if(i + 1 < n) sum += g[i+1][j]; if(j + 1 < n) sum += g[i][j+1]; if(j - 1 >= 0) sum += g[i][j-1]; if(sum % 2 != 0 ) { flag = 1; break; } } if(flag) break; } if(!flag) printf("YES\n"); else printf("NO\n"); }}
- CF #263 (Div. 2) A
- CF#263 (Div. 1) A
- cf 190div 2 A
- CF #230 (Div. 2) A
- CF#257 (Div. 2) A.
- CF#256 (Div. 2) A.
- CF#FF (Div. 2) A .
- CF#253 (Div. 2) A.
- CF#258 (Div. 2) A.
- CF#252 (Div. 2) A.
- CF#250 (Div. 2) A .
- CF#259 (Div. 2) A.
- CF #260 (Div. 2)A
- CF #261 (Div. 2) A
- CF#264 (Div. 2) A.
- CF #266 (Div. 2) A.
- CF#267 (Div. 2) A
- CF#268 (Div. 2) A.
- android图像绘制(六)——获取本地图片或拍照图片
- 一致性哈希
- Android的AsyncTask的简单介绍
- Android_访问网络一(使用HttpURLConnection访问)
- Hibernate 延迟加载
- CF #263 (Div. 2) A
- Oracle 11g win32位 window7下安装教程
- 查找算法
- 管道的故事(二)提桶者和管道创建者
- WEB项目设置session有效期
- 加州理工学院公开课:机器学习与数据挖掘_训练与测试(第五课)
- opencv 安装 以及PIL 安装主要参考http://blog.csdn.net/sunlylorn/article/details/7907698 部分软件包过老需要自己手动下载
- 从头说12种排序算法:原理、图解、动画视频演示、代码以及笔试面试题目中的应用 .
- 2014—暑期学习总结