B. Flag of Berland
1 second
256 megabytes
standard input
standard output
The flag of Berland is such rectangular field n × m that satisfies following conditions:
- Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
- Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
- Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
YES
4 3
BRG
BRG
BRG
BRG
YES
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
NO
4 4
RRRR
RRRR
BBBB
GGGG
NO
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.
这题还是不错的,题意是如果 可以分割成3条,R G B各一条,那就输出YES,每条可以包含多行,但是每条的行数必须相等
打了一大堆补丁,最后过了
n,m = map(int,raw_input().split())
mark = 1
s = []
for i in range(n):
tmp = raw_input();
s.append(tmp);
for c in range(m):
if c + 1 < m and tmp[c] != tmp[c + 1]:
mark = 0;
r = 0
g = 0
b = 0
for a in s:
for c in a:
if c =='R':
r = r + 1
if c == 'G':
g = g + 1
if c == 'B':
b = b + 1
if mark == 1:
num = 1
w = []
for i in range(n):
if i + 1 < n and s[i][0] == s[i + 1][0]:
num = num + 1;
else:
w.append(int(num))
num = 1;
for i in range(len(w)):
if i + 1 < len(w) and w[i] != w[i + 1]:
mark = 2;
if mark == 1 and len(w) == 3 and r == g and g == b:
print "YES"
else:
print "NO"
else :
for y in range(m):
for x in range(n):
if x + 1 < n and s[x][y] != s[x + 1][y]:
mark = 2;
break;
if mark == 2:
print "NO"
else :
num = 1
w = []
for i in range(m):
if i + 1 < m and s[0][i] == s[0][i + 1]:
num = num + 1
else:
w.append(int(num));
num = 1;
for i in range(len(w)):
if i + 1 < len(w) and w[i] != w[i + 1]:
mark = 2;
if mark == 0 and len(w) == 3 and r == g and g ==b:
print "YES"
else:
print "NO"
B. Flag of Berland的更多相关文章
- Codefroces Educational Round 26 837 B. Flag of Berland
B. Flag of Berland time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- AC日记——Flag Codeforces 16a
A. Flag time limit per test 2 seconds memory limit per test 64 megabytes input standard input output ...
- CF16A Flag
CF16A Flag 题意翻译 题目描述 根据一项新的ISO标准,每一个国家的国旗应该是一个n×m的格子场,其中每个格子最多有10种不同的颜色.并且国旗应该有条纹:旗帜的每一行应包含相同颜色的方块,相 ...
- Educational Codeforces Round 26 B,C
B. Flag of Berland 链接:http://codeforces.com/contest/837/problem/B 思路:题目要求判断三个字母是否是条纹型的,而且宽和高相同,那么先求出 ...
- Educational Codeforces Round 26 A B C题
题目链接 A. Text Volume 题意:计算句子中,每个单词大写字母出现次数最多的那个的出现次数(混不混乱QAQ). 解题思路:注意getchar()就没啥了. #include<cstd ...
- Codeforces Round #207 (Div. 2)A B C E 水 思路 set 恶心分类
A. Group of Students time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 26
Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...
- Codeforces Round #375 (Div. 2) D. Lakes in Berland dfs
D. Lakes in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- B. Berland Bingo
Lately, a national version of a bingo game has become very popular in Berland. There are n players p ...
随机推荐
- 【HDU 2028】Lowest Common Multiple Plus
Problem Description 求n个数的最小公倍数. Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数. Output 为每组测试数据输出它们的最小公倍数 ...
- 2018 GDCPC 省赛总结
第二次参加省赛了,对比上年连STL都不会的acm入门者来说, 今年是接触acm的第二年. 首先要说的是今年的省赛比上年人数多了很多, 闭幕式200多支队伍坐满了整个礼堂还要站着不少人,所以今年的竞争其 ...
- python021 Python3 错误和异常
Python3 错误和异常 作为Python初学者,在刚学习Python编程时,经常会看到一些报错信息,在前面我们没有提及,这章节我们会专门介绍. Python有两种错误很容易辨认:语法错误和异常. ...
- iOS-runtime-objc_setAssociatedObject(关联对象以及传值)
例子: static const char kRepresentedObject; - (IBAction)doSomething:(id)sender { UIAlertView *alert = ...
- Ubuntu安装sublime Text 3并配置可以输入中文
使用Ubuntu系统后,想找一个顺手的编辑器,sublime作为我的首选编辑器,在安装和配置可输入中文时遇到各种个样的问题,总结一些: 1:问题: 我的系统是Ubuntu 18.04 LTS,尝试多次 ...
- 《effective C++》:条款37——绝不重新定义继承而来的缺省参数值
引子: 阿里的一道题: #include <IOSTREAM> using namespace std; class A{ public: ) { cout<<"a~ ...
- Fedora20 安装 MySQL
参考资料: http://www.cnblogs.com/focusj/archive/2011/05/09/2057573.html http://linux.chinaunix.net/techd ...
- P1359 租用游艇 洛谷
https://www.luogu.org/problem/show?pid=1359 题目描述 长江游艇俱乐部在长江上设置了n 个游艇出租站1,2,…,n.游客可在这些游艇出租站租用游艇,并在下游的 ...
- 洛谷——P1547 Out of Hay
P1547 Out of Hay 题目背景 奶牛爱干草 题目描述 Bessie 计划调查N (2 <= N <= 2,000)个农场的干草情况,它从1号农场出发.农场之间总共有M (1 & ...
- Java实验--关于简单字符串回文的递归判断实验
首先题目要求写的是递归的实验,一开始没注意要求,写了非递归的方法.浪费了一些时间,所谓吃一堑长一智.我学习到了以后看实验的时候要认真看实验中的要求,防止再看错. 以下是对此次的实验进行的分析: 1)递 ...