zoukankan      html  css  js  c++  java
  • [CF837B] Flag of Berland(乱写)

    题意: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 }
  • 相关阅读:
    深浅拷贝的区别
    vue中动态加载组件
    一些工具软件
    echarts 自传作品入口
    Echarts progress 设置背景颜色
    Echarts柱状图,柱子设置不一样的渐变色
    .net 控制台学习笔记 一、控制台程序的异常捕获
    IdentityServer4实战:自定义用户名和密码校验
    IdentityServer4实战:Token 中返回用户属性
    IdentityServer4实战:持久化 Resource
  • 原文地址:https://www.cnblogs.com/kirai/p/7295489.html
Copyright © 2011-2022 走看看