题意:http://codeforces.com/contest/837/problem/B
判断给定二维阵是否是个条形旗,条形旗符合条件:
- 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.
没什么特别的,就是想记录一下骚操作。。
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const int maxn = 110; 5 int n, m; 6 char a[maxn][maxn], b[maxn][maxn]; 7 int vis[256]; 8 9 bool ok() { 10 return 11 (!vis['R'] && !vis['G'] && vis['B']) || 12 (!vis['R'] && vis['G'] && !vis['B']) || 13 (vis['R'] && !vis['G'] && !vis['B']); 14 } 15 16 signed main() { 17 // freopen("in", "r", stdin); 18 while(~scanf("%d%d",&n,&m)) { 19 memset(a, 0, sizeof(a)); 20 memset(b, 0, sizeof(b)); 21 memset(vis, 0, sizeof(vis)); 22 for(int i = 0; i < n; i++) scanf("%s", a[i]); 23 for(int i = 0; i < n; i++) { 24 for(int j = 0; j < m; j++) { 25 b[j][i] = a[i][j]; 26 vis[a[i][j]]++; 27 } 28 } 29 if(!(vis['R'] == vis['G'] && vis['G'] == vis['B'])) { 30 puts("NO"); 31 continue; 32 } 33 bool ok1 = 1, ok2 = 1; 34 for(int i = 0; i < n; i++) { 35 bool t1 = 1; 36 memset(vis, 0, sizeof(vis)); 37 for(int j = 0; j < m; j++) vis[a[i][j]]++; 38 if(!ok()) t1 = 0; 39 if(!t1) ok1 = 0; 40 } 41 for(int i = 0; i < m; i++) { 42 bool t2 = 1; 43 memset(vis, 0, sizeof(vis)); 44 for(int j = 0; j < n; j++) vis[b[i][j]]++; 45 if(!ok()) t2 = 0; 46 if(!t2) ok2 = 0; 47 } 48 ok1 &= ((unique(b[0], b[0]+n) - b[0]) == 3); 49 ok2 &= ((unique(a[0], a[0]+m) - a[0]) == 3); 50 if(ok1 || ok2) puts("YES"); 51 else puts("NO"); 52 } 53 return 0; 54 }