A. Brain's Photos

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.

As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).

Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!

As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.

Photo can be represented as a matrix sized n × m, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:

  • 'C' (cyan)

  • 'M' (magenta)

  • 'Y' (yellow)

  • 'W' (white)

  • 'G' (grey)

  • 'B' (black)

The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively.

Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.

Output

Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.

Examples

input

2 2  C M  Y Y

output

#Color

input

3 2  W W  W W  B B

output

#Black&White

input

1 1  W

output

#Black&White

____________________

题意:一张照片用矩阵n * m 表示,里面有C M Y W G B 几种颜色,判断这张照片是否是黑白照(黑白照只有W G B 三种)

程序应该还是比较好写的,一开始无脑写了一个版本是:

#include<iostream>

using namespace std ;

string s[100];

int main()

{

int n , m ;

cin >> n >> m ;

int flag = 0 ;

for ( int i = 0 ; i < n ; i++ )

{

for ( int j = 0 ; j < m ; j++ )

{

cin>>s[i][j] ;

}

}

for ( int i = 0 ; i < n ; i++ )

{

for ( int j = 0 ; j < m ; j++ )

{

switch(s[i][j])

{

case'C':

case'M':

case'Y':

flag = 1 ; break ;

default : continue ;

}

 }

}

if(flag == 1 ) 

cout << "#Color"<< endl ;

else cout <<"#Black&White" << endl ;

return 0 ; 

}

这样的话,大概时间复杂度在1W左右,应该能A,还是runtime error (但是在本机评测的话RE的数据可以在4.6s跑完,不知道是TLE了还是又是代码写的还会导致segment fault) 。

我在这里认为既然本机4.6s能跑完,应该是TLE了。于是怀疑被无数ACMer所诟病的cin cout 的效率,于是用scanf printf改写:

//#include<iostream>

//using namespace std ;

#include<cstdio>

char s[110][110];

int main()

{

int n , m ;

//freopen("2.txt","r",stdin);

scanf("%d %d",&n,&m);

int flag = 0 ;

for ( int i = 0 ; i < n ; i++ )

{

for ( int j = 0 ; j < m ; j++ )

{

//cin>>s[i][j] ;

scanf("%s",&s[i][j]);

switch(s[i][j])

{

case'C':

case'M':

case'Y':

flag = 1 ; break ;

default : continue ;

}

} 

}

if(flag == 1 ) 

//cout << "#Color"<< endl ;

printf("#Color\n");

else //cout <<"#Black&White" << endl ;

printf("#Black&White\n");

return 0 ; 

}

成功AC。

但是这个还是有优化空间的,发现开了那么大数组其实根本没必要使用。

最后优化一下代码:

#include<cstdio>

int main()

{

int n , m ;

scanf("%d %d",&n,&m);

int flag = 0 ;

char t[2];

for ( int i = 0 ; i < n ; i++ )

{

for ( int j = 0 ; j < m ; j++ )

{

//cin>>s[i][j] ;

scanf("%s",&t);

switch(t[0])

{

case'C':

case'M':

case'Y':

flag = 1 ; break ;

default : continue ;

}

} 

}

if(flag == 1 ) 

//cout << "#Color"<< endl ;

printf("#Color\n");

else //cout <<"#Black&White" << endl ;

printf("#Black&White\n");

return 0 ; 

}

这里似乎还是有字符串的问题,一开始蠢了字符串开成了char t[1];还错了好几次,貌似我访问t[1]访问到了m的地址,于是t[0]存放字符,t[1]把m的值改变了导致非常奇怪的跑法。

ps:在这里之所以我总是不甘心的用%s 字符串处理,是为了处理空格。

最后 AC记录:

A. Brain's Photos ——Codeforces Round #368 (Div. 2)的更多相关文章

  1. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

  2. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  3. Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)

    Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...

  4. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  5. Codeforces Round #368 (Div. 2) A. Brain's Photos 水题

    A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...

  6. Codeforces Round #368 (Div. 2)A B C 水 图 数学

    A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. Codeforces Round #368 (Div. 2) A , B , C

    A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #368 (Div. 2) A

    Description Small, but very brave, mouse Brain was not accepted to summer school of young villains. ...

  9. Codeforces Round #368 (Div. 2) D. Persistent Bookcase

    Persistent Bookcase Problem Description: Recently in school Alina has learned what are the persisten ...

随机推荐

  1. C#与C++中struct和class的小结

    在C#中,struct其实也是可以像class一样封装方法和数据的.请参考如下代码. using System; namespace testDiffInStructClass { public st ...

  2. sap 设备cnsapwin不支持页格式*****

    SAP SMARTFORMS 打印 CNSAPWIN 不支持页格式 解决办法: 在smartforms里的表格属性虽然定义了要打印的页格式 ZUNIA5 ,但是打印时会提示错误:" CNSA ...

  3. 关于:1.指针与对象;2.深浅拷贝(复制);3.可变与不可变对象;4.copy与mutableCopy的一些理解

    最近对深浅拷贝(复制)做了一些研究,在此将自己的理解写下来,希望对大家有所帮助.本人尚处在摸索阶段,希望各位予以指正. 本文包括如下方向的探索: 1.指针与对象: 2.深/浅拷贝(复制): 3.可变/ ...

  4. synchronized细节问题

    一.synchronized有锁重入的特点,某个线程得到对象的锁后,再次请求此对象可以再次得到改对象的锁.如下示例,在method1中调用method2,在method2中调用method3,而met ...

  5. js获取json的value

    getJson('age'); function getJson(key){ var jsonObj={"name":"cxr","age" ...

  6. 重点+超详细:ajax和json及案例

    不用jQuery的ajax流程 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "ht ...

  7. 字符串:"2016-09-21T18:57:50+08:00[Asia/Chungking]" 转Date

    public static void main(String[] args) throws Exception { Date date1 = new Date(); SimpleDateFormat ...

  8. QT 报错:Project ERROR: Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild.

    1.打开终端,输入指令并按回车键: sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer 2.如果电脑设置有密码,终 ...

  9. Django 1.8 - “No migrations to apply” when run migrate after makemigrations 解决办法

    解决办法 1 删除应用migrations目录 2 删除MySQL中django_migrations中对应的行(delete from django_migrations where app='ap ...

  10. 淘淘商城_day07_课堂笔记

    今日大纲 讲解订单系统 基于订单系统完成下单功能的开发 使用Solr完成商品的搜索功能 订单系统 说明:订单系统只是做讲解,不做开发. 导入taotao-order 表结构 订单表: 订单商品表: 疑 ...