CF Flag of Berland
来源:互联网 发布:上海迪士尼门票 知乎 编辑:程序博客网 时间:2024/06/05 15:35
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 5RRRRRRRRRRBBBBBBBBBBGGGGGGGGGG
YES
4 3BRGBRGBRGBRG
YES
6 7RRRGGGGRRRGGGGRRRGGGGRRRBBBBRRRBBBBRRRBBBB
NO
4 4RRRRRRRRBBBBGGGG
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.
分析:三个字母R,G,B的排列,代表三面旗帜,所以相同字母肯定要在一起,如果是按行排的话,则要每一排都要
是相同的字母,如果是按列排的话,每一列都要是相同的字母,如果满足条件就输出YES,否则输出NO,本题
要考虑三个点,第一,三种字母的数量相等,第二,如果是按行排,则每一行的字母要相同,如果是竖着排,则
每列的字母要相同。第三,相同的字母应排在一起,如果这一点不好理解,下面来看一组测试数据:
6 5
RRRRR
GGGGG
BBBBB
BBBBB
GGGGG
RRRRR
这组数据答案应该是NO。
#include <iostream>#include<stdio.h>#include<string.h>using namespace std;int main(){ int n,m,bj1,bj2,ee; int h[3]={0}; scanf("%d %d",&n,&m); char s[n][m]; getchar(); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { scanf("%c",&s[i][j]); if(s[i][j]=='R') { h[0]++; } if(s[i][j]=='G') { h[1]++; } if(s[i][j]=='B') { h[2]++; } } getchar(); } bj1=0; bj2=0; for(int i=0;i<n;i++) { for(int j=0;j<m-1;j++) { if(s[i][j]!=s[i][j+1]) { bj1=1; } } } for(int i=0;i<m;i++) { for(int j=0;j<n-1;j++) { if(s[j][i]!=s[j+1][i]) { bj2=2; } } } if(h[0]==h[1]&&h[0]==h[2]) { if(bj1==0&&n%3==0) { ee=0; for(int i=0;i<n-1;i++) { if(s[i][0]!=s[i+1][0]) { ee+=1; } } if(ee==2) printf("YES\n"); else printf("NO\n"); } else if(bj2==0&&m%3==0) { ee=0; for(int i=0;i<m-1;i++) { if(s[0][i]!=s[0][i+1]) { ee+=1; } } if(ee==2) printf("YES\n"); else printf("NO\n"); } else printf("NO\n"); } else printf("NO\n"); return 0;}
- CF Flag of Berland
- codeforces 837B Flag of Berland
- Berland Flag
- Educational Codeforces Round 26:B. Flag of Berland
- Educational Codeforces Round 26 B. Flag of Berland
- codeforce 837B Flag of Berland(矩形判断)
- codeforces837B Flag on Berland
- cf 16a Flag
- CF 25C Roads in Berland
- CF 1C Ancient Berland Circus
- CF 567B Berland National Library
- CF 567B Berland National Library
- Lakes in Berland(CF #375 Div. 2)
- CF-25C - Roads in Berland(水题)
- CF#1C Ancient Berland Circus(正多边形最小面积)
- CF 567B(Berland National Library-看成折线图)
- CF - 723D Lakes in Berland,bfs+sort
- codeforces A. Parliament of Berland【水】
- 在Intellij Idea中jstl声明报错解决
- Ajax进阶一
- curator对Zookeeper节点监听总结
- Spring-整合多个配置文件
- 编译器的安装
- CF Flag of Berland
- 改变 AfxMessageBox() 的标题
- 读前辈的大话设计模式(十一)之观察者模式,抒自己的读后感
- fedora25下protobuf安装过程
- 2017百度之星资格赛:1005. 寻找母串(卡特兰数+分块打表)
- 单例模式--懒汉模式
- CI框架的base_url localhost [::1]等问题
- 句子反转与手摇算法
- 【剑指offer】面试题65:不用加减乘除做加法