zoukankan      html  css  js  c++  java
  • Codefroces Educational Round 26 837 B. Flag of Berland

    B. Flag of Berland
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard 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.

    大模拟,n m被三整除

    #include <iostream> 
    #include <algorithm> 
    #include <cstring> 
    #include <cstdio>
    #include <vector> 
    #include <queue> 
    #include <cstdlib> 
    #include <iomanip>
    #include <cmath> 
    #include <ctime> 
    #include <map> 
    #include <set> 
    using namespace std; 
    #define lowbit(x) (x&(-x)) 
    #define max(x,y) (x>y?x:y) 
    #define min(x,y) (x<y?x:y) 
    #define MAX 100000000000000000 
    #define MOD 1000000007
    #define pi acos(-1.0) 
    #define ei exp(1) 
    #define PI 3.141592653589793238462
    #define ios() ios::sync_with_stdio(false)
    #define INF 0x3f3f3f3f 
    #define mem(a) (memset(a,0,sizeof(a))) 
    typedef long long ll;
    int n,m;
    char s[105][105];
    char name[4]={'B','G','R'};
    bool check(int x,int n,int y,int m,char c)
    {
        for(int i=x;i<=n;i++)
        {
            for(int j=y;j<=m;j++)
            {
                if(s[i][j]!=c) return false;
            }
        }
        return true;
    }
    int main()
    {
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
            scanf("%s",s[i]+1);
        bool flag=false;
        do
        {
            if(n%3==0)
            {
                bool falg=true;
                for(int i=0;i<3;i++)
                {
                    if(!check(i*n/3+1,(i+1)*n/3,1,m,name[i])) falg=false;
                }
                if(falg)flag=true;
            }
            if(m%3==0)
            {
                bool falg=true;
                for(int i=0;i<3;i++)
                {
                    if(!check(1,n,i*m/3+1,(1+i)*m/3,name[i])) falg=false;
                }
                if(falg)flag=true;
            }
        }while(next_permutation(name,name+3));
        puts(flag?"YES":"NO");
        return 0;
    }
  • 相关阅读:
    echarts二维坐标这样写出立体柱状图
    echarts中使图表循环显示tooltip-封装tooltip的方法轮询显示图表数据
    webpack--运行npm run dev自动打开浏览器以及热加载
    exports、module.exports和export、export default到底是咋回事,区别在哪里
    H5页面判断客户端是iOS或是Android并跳转对应链接唤起APP
    关于页面锚点跳转以及万能锚点跳转插件
    echarts Map 省份文字居中,即对应地图中心位置
    Moment.js 常见用法,常见API
    Tomcat 不加载图片验证码
    Cglib 动态代理
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7285526.html
Copyright © 2011-2022 走看看