CodeForces-16A-Flag

原创 2016年05月31日 22:22:52

Description

According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland’s government asked you to find out whether their flag meets the new ISO standard.

Input

The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.

Output

Output YES, if the flag meets the new ISO standard, and NO otherwise.

Sample Input
Input

3 3
000
111
222

Output

YES

Input

3 3
000
000
111

Output

NO

Input

3 3
000
111
002

Output

NO

横着一样,竖着不一样
直接暴力找

  #include<iostream>  
    #include<cstdlib>  
    #include<cstring>  
    #include<cstdio>  
    #include<cmath>  
    #include<vector>  
    #include<string>  
    #include<queue>  
    #include<map>  
    #include<algorithm>  
    using namespace std;  
    const int maxn=1e3+10;  
    int n,m;  
    char s[maxn][maxn];  

    int main()  
    {  
        while(~scanf("%d%d",&n,&m))  
        {  
            int flag=1;  
            for (int i=0;i<n;i++)  
            {  
                scanf("%s",s[i]);  
                for (int j=0;j<m;j++)  
                {  
                    if (j&&s[i][j]!=s[i][j-1]) flag=0;  
                    if (i&&s[i][j]==s[i-1][j]) flag=0;  
                }  
            }  
            printf("%s\n",flag?"YES":"NO");  
        }  
        return 0;  
    }  
版权声明:本文为博主原创文章,未经博主允许不得转载。

CodeForces 16A Flag

Description According to a new ISO standard, a flag of every country should have a chequered fiel...

codeforces 16A - Flag

旗的每一行内颜色相同,相邻行间颜色不同 #include #include #include #include #include #include #include #includ...
  • ymrfzr
  • ymrfzr
  • 2013年05月29日 08:59
  • 403

codeforces837B Flag on Berland

cf837B题解

Educational Codeforces Round 26 B. Flag of Berland

题目网址: Educational Codeforces Round 26 B. Flag of Berland题意分析:题意: 问这个旗子 满不满足一下条件 有三条线, 且三条线颜色不一样, 宽度...

CodeForces 18E Flag 2

Description According to a new ISO standard, a flag of every country should have, strangely enoug...

codeforces 16 E 简单概率DP

http://codeforces.com/problemset/problem/16/E 题意:有n条鱼,每天恰好会有一对鱼相遇,并且其中的一条会吃掉另一条,给你一个n*n的矩阵,a[i][j]表...

Educational Codeforces Round 16 C. Magic Odd Square (构造)

链接C. Magic Odd Square题意构造一个n*n的矩阵,n为奇数,矩阵中的每个数都是1到n^2中的一个且不能重复,使得这个矩阵的每一行,每一列还有主对角线中数的和均为奇数。思路首先想到的是...

Educational Codeforces Round 16 -- E. Generate a String (DP)

大体题意: 一开始你有一个空的字符串,你要得到n 个‘a’字符,  你插入或者删除一个‘a’需要x秒,复制目前的字符串需要y秒,求最少多少秒! 思路: 赛后补得,没有时间做了= =! dp思想...

Educational Codeforces Round 16 A. King Moves【模拟】

原题链接:http://codeforces.com/contest/710/problem/A 题意:在国际象棋上,给你将的位置,问你它可以走多少个方向。 AC代码:...

Codeforces Beta Round #16 (Div. 2 Only) E. Fish

明显的概率dp dp[st],st是当前鱼的一个集合,
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:CodeForces-16A-Flag
举报原因:
原因补充:

(最多只允许输入30个字)