codeforce 837B Flag of Berland(矩形判断)
来源:互联网 发布:协同工作软件 编辑:程序博客网 时间:2024/06/11 21:22
B. Flag of Berland
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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).
Input
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.
Output
Print “YES” (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print “NO” (without quotes).
Examples
input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
output
YES
input
4 3
BRG
BRG
BRG
BRG
output
YES
input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
output
NO
input
4 4
RRRR
RRRR
BBBB
GGGG
output
NO
Note
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.
题目非常简单,就是判断一下这一面旗帜是不是有三个大小相同的矩形区域组成,也可以理解为有两条支线分割出完全相同的三部分,且颜色不同
题目很简单,但很容易翻车,准备的数据很少,但最后hack掉了一堆人。我用的就是判断这三个区域的大小,应为左上角和右下角肯定是不同的,就在边界找到与他们相同的,记录长度与宽带,最后要判断三个矩形区域面积和是否和大面积相等,然后要再判断下这个区域是否颜色完全相同(本人就这里。。没判断)
代码如下:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;const int MAX = 110;char Map[MAX][MAX];bool book[300];int n,m;bool solve(){ memset(book,0,sizeof(book)); // if((n < 3) && (m < 3)) return false; if((n % 3!= 0)&&(m % 3!=0)) return false; int w1 = 0,h1 = 0; book[Map[0][0]] = true; for(int i=0;i<n;i++) if(Map[i][0] == Map[0][0]) h1++; else break; for(int i=0;i<m;i++) if(Map[0][i] == Map[0][0]) w1++; else break; for(int i=0;i<h1;i++) for(int j=0;j<w1;j++) if(Map[i][j] != Map[0][0]) return false; int w2 = 0,h2 = 0; for(int i=n-1;i>=0;i--) if(Map[i][m-1] == Map[n-1][m-1] && !book[Map[i][m-1]] ) h2++; else break; for(int i=m-1;i>=0;i--) if(Map[n-1][i] == Map[n-1][m-1] && !book[Map[n-1][i]]) w2++; else break; for(int i=n-1;i>=(n-h2);i--){ for(int j=m-1;j>=(m-w2);j--) if(Map[i][j] != Map[n-1][m-1]) return false; } book[Map[n-1][m-1]] = true; int x = 0,y = 0; for(int i=0;i<n;i++){ bool isok = false; for(int j=0;j<m;j++){ if(!(i<h1&&j<w1)){ x = i;y = j; isok = true; break; } } if(isok) break; } int w3 = 0,h3 = 0; for(int i=y;i<m;i++) if(Map[x][i] == Map[x][y] && !book[Map[x][i]]) w3++; else break; for(int i=x;i<n;i++) if(Map[i][y] == Map[x][y] && !book[Map[i][y]]) h3++; else break; for(int i=x;i<x+h3;i++) for(int j=y;j<y+w3;j++) if(Map[i][j] != Map[x][y]) return false; // printf("%d,%d,%d,%d,%d\n",w1,h1,w2,h2,w3,h3); if((h1 == h2 && h2 == h3 && w1 == w2 && w2 == w3) &&(h1*w1+h2*w2+h3*w3 == n*m)) return true; return false;}int main(void){ // freopen("1.txt","r",stdin); scanf("%d %d",&n,&m); for(int i=0;i<n;i++) scanf("%s",Map[i]); if(solve()) printf("YES\n"); else printf("NO\n"); return 0;}
- codeforce 837B Flag of Berland(矩形判断)
- codeforces 837B Flag of Berland
- CF Flag of Berland
- Educational Codeforces Round 26:B. Flag of Berland
- Educational Codeforces Round 26 B. Flag of Berland
- 【codeforce】B. Flag Day
- Berland Flag
- codeforces837B Flag on Berland
- codeforce 676b Pyramid of Glasses
- codeforce 804B Minimum number of steps
- codeforce 804B Minimum number of steps
- flag for codeforce
- B. Berland National Library
- B. Berland Bingo----模拟
- codeforce#375D. Lakes in Berland
- codeforce 1C Ancient Berland Circus
- codeforce 1C Ancient Berland Circus
- Codeforce 143B - Help Kingdom of Far Far Away 2
- Spring整合Spring Session,用redis解决分布式session共享问题
- Vector3.Distance
- OpenCV学习——图像坐标系,相机坐标系和世界坐标系
- Reveal :Xcode辅助界面调试工具
- HDFS的实现思想
- codeforce 837B Flag of Berland(矩形判断)
- Android开发中常见的内存泄漏情况和解决办法
- Longest Ordered Subsequence
- 2017年Android Studio做NDK情况调查
- mybatis generator无法将数据表中text字段映射问题
- IE9下js无效,打开开发者模式有效
- Transform.RotateAround
- iOS开发 MFMessageComposeViewController(发送短信)的使用
- php中正则表达式详解