Educational Codeforces Round 26 B. Flag of Berland
来源:互联网 发布:vscode 支持maven吗 编辑:程序博客网 时间:2024/05/20 03:41
题目网址: Educational Codeforces Round 26 B. Flag of Berland
题意分析:
题意:
- 问这个旗子 满不满足一下条件
- 有三条线, 且三条线颜色不一样, 宽度, 高度, 都相等, 且平行
- 每一条线只有一种颜色
思路:
- 暴力判断即可
- 从行的角度来判断是否是三条线, 是否每条线等宽等高,是否颜色不一样
- 从列的角度同行
代码:
#include <bits/stdc++.h>using namespace std;const int SIZE = 105;char flag[SIZE][SIZE];int n, m;bool judge_hang(){ int color[200]; memset(color, 0, sizeof(color)); int t1 = n / 3, t2 = n * 2 / 3, t3 = n; char tmpColor = flag[0][0]; color[(int)tmpColor] = 1; for (int i = 0; i < t1; ++i) { for (int j = 0; j < m; ++j) { if(flag[i][j] != tmpColor) { return false; } } } tmpColor = flag[t1][0]; if(color[(int)tmpColor]) return false; else { color[(int)tmpColor] = 1; for (int i = t1; i < t2; ++i) { for (int j = 0; j < m; ++j) { if(flag[i][j] != tmpColor) { return false; } } } } tmpColor = flag[t2][0]; if(color[(int)tmpColor]) return false; else { for (int i = t2; i < t3; ++i) { for (int j = 0; j < m; ++j) { if(flag[i][j] != tmpColor) { return false; } } } } return true;}bool judge_lie(){ int color[200]; int t1 = m / 3, t2 = m * 2 / 3, t3 = m; memset(color, 0, sizeof(color)); char tmpColor = flag[0][0]; color[(int)tmpColor] = 1; for (int i = 0; i < t1; ++i) { for (int j = 0; j < n; ++j) { if(flag[j][i] != tmpColor) { return false; } } } tmpColor = flag[0][t1]; if(color[(int)tmpColor]) return false; else { color[(int)tmpColor] = 1; for (int i = t1; i < t2; ++i) { for (int j = 0; j < n; ++j) { if(flag[j][i] != tmpColor) { return false; } } } } tmpColor = flag[0][t2]; if(color[(int)tmpColor]) return false; else { color[(int)tmpColor] = 1; for (int i = t2; i < t3; ++i) { for (int j = 0; j < n; ++j) { if(flag[j][i] != tmpColor) { return false; } } } } return true;}int main(int argc, char const *argv[]){ scanf("%d %d", &n, &m); getchar(); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { scanf("%c", &flag[i][j]); } getchar(); } if(n % 3 && m % 3) { printf("NO\n"); return 0; } else { if(n % 3 == 0) { if(judge_hang()) { printf("YES\n"); return 0; } } if(m % 3 == 0) { if(judge_lie()) { printf("YES\n"); return 0; } } printf("NO\n"); } return 0;}
阅读全文
0 0
- Educational Codeforces Round 26:B. Flag of Berland
- Educational Codeforces Round 26 B. Flag of Berland
- codeforces 837B Flag of Berland
- Educational Codeforces Round 26 B
- Educational Codeforces Round 15 B. Powers of Two
- Educational Codeforces Round 15, problem: (B) Powers of Two
- Educational Codeforces Round 15 B. Powers of Two (数学)
- Educational Codeforces Round 15 B Powers of Two
- Educational Codeforces Round 5 B
- Educational Codeforces Round 3 B
- Educational Codeforces Round 20 B
- Educational Codeforces Round 23 B
- CF Flag of Berland
- Educational Codeforces Round 26
- Educational Codeforces Round 26
- codeforce 837B Flag of Berland(矩形判断)
- Educational Codeforces Round 26 A B C 三道水题
- Educational Codeforces Round 1(B)
- Ubuntu 配置 LAMP 环境
- java面试题,各大企业常见的java笔试题之四
- FrameAnimDrawable
- 系统管理员应该知道的 20 条 Linux 命令
- 单链表的基本操作(创建,删除,增加,反向)
- Educational Codeforces Round 26 B. Flag of Berland
- Java NIO
- Python玩转数据分析学习笔记-03数据获取
- 运算符和表达式(优先级)
- Android Material Design 之 CoordinatorLayout
- PE文件格式 super版
- 广度优先搜索(BFS)
- Android Material Design 之 CoordinatorLayout + FloatingActionButton
- PHP CSS3 目录直读式Lightbox 画廊图片展示