Codeforce_837B - Flag of Berland

B. Flag of Berland
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.

wa了两天,终于a了,说实话我也表达不出,但是就是模拟解决问题

#include
#include
#include
#include
#include
using namespace std;
int main()
{
    int n,m,i,j;
    string str[111],str1[111];
    while(cin>>n>>m)
    {

        for(i=0; i1; i++)
            str[i].clear();
        for(i=0; i>str[i];
        /*   for(i=0;i
        if(n%3!=0&&m%3!=0)
        {
            puts("NO");

        }
        else
        {
            map<char,int> q;
            q.clear();
            int t1=0,t2=0;
            int s1=-1,s2=-1,s3=-1,ss1=-1,ss2=-1,ss3=-1;
            if(n%3==0)
            {
                s1=s2=s3=0;
                int t=n/3;
                t1=t*m;

                for(i=0; ifor(j=0; jif(str[i][j]==str[0][0]&&!q[str[0][0]])
                            s1+=1;
                    }
                }
                q[str[0][0]]=1;
                for(i=t; i<2*t; i++)
                {
                    for(j=0; jif(str[i][j]==str[t][0]&&!q[str[t][0]])
                            s2+=2;
                    }
                }
                q[str[t][0]]=1;
                for(i=2*t; i<3*t; i++)
                {
                    for(j=0; jif(str[i][j]==str[2*t][0]&&!q[str[2*t][0]])
                            s3+=3;
                    }
                }
                q[str[2*t][0]]=1;
            }
            if(m%3==0)
            {
                q.clear();
                ss1=ss2=ss3=0;
                int t=m/3;
                t2=t*n;
                for(i=0; ifor(j=0; jif(str[j][i]==str[0][0]&&!q[str[0][0]])
                            ss1+=1;
                        //    cout<
                    }
                    //  puts("");
                }
                q[str[0][0]]=1;
                for(i=t; i<2*t; i++)
                {
                    for(j=0; jif(str[j][i]==str[0][t]&&!q[str[0][t]])
                            ss2+=2;
                        //   cout<
                    }
                    // puts("");
                }
                q[str[0][t]]=1;
                for(i=2*t; ifor(j=0; jif(str[j][i]==str[0][2*t]&&!q[str[0][2*t]])
                            ss3+=3;
                    }
                }
                q[str[0][2*t]]=1;

            }
          //  cout<
            if(s1==t1&&s2==2*t1&&s3==3*t1)
            {
                // puts("1");
                puts("YES");
            }
            else if(ss1==t2&&ss2==2*t2&&ss3==3*t2)
            {
                // puts("2");

                  puts("YES");
            }
            else
            {
                //  puts("3");
                puts("NO");
            }

        }
        //  cout<

    }

    return 0;
}

你可能感兴趣的:(cf,模拟)