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;
    }
  • 相关阅读:
    jQuery before 和 after
    pm2常用的命令
    git 常见命令
    Number 和 parseInt 区别
    枚举创建单例模式 安全 而且利用反射也读不到
    spring 的数据库工具类 JDBCTemplate
    阿里druid数据库连接及配置文件
    java C3P0连接数据库
    JDBC利用.properties文件连接数据库
    JDBC工具类的使用
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7285526.html
Copyright © 2011-2022 走看看