您的位置:首页 > 大数据 > 人工智能

Codeforces Problem 707A Brain's Photos(水题)

2016-08-21 10:23 351 查看
此文章可以使用目录功能哟↑(点击上方[+])

比赛链接→Codeforces Round #368 (Div. 2)




 Codeforces Problem 707A Brain's Photos

Accept: 0    Submit: 0

Time Limit: 2 seconds    Memory Limit : 256 megabytes




 Problem Description

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.



 Sample Input

2 2

C M

Y Y

3 2

W W

W W

B B

1 1

W



 Sample Output

#Color

#Black&White

#Black&White



 Hint



 Problem Idea

解题思路:

【题意】

给你一张n*m像素大小的照片

每个像素点有一种颜色,用字母表示

'C'表示青色

'M'表示紫红色

'Y'表示黄色

'W'表示白色

'G'表示灰色

'B'表示黑色

问该照片是黑白照(只包含白色、灰色、黑色三种颜色,即只包含字母'W'、'G'、'B')还是彩色照

【类型】
implementation

【分析】
照片是黑白照,还是彩色照,取决于是否有除了黑白灰三种以外的其他颜色,也就是是否会有'C'、'M'、'Y'三种颜色出现,如果出现了,就是彩色照;否则就是黑白照,我们只需要枚举每个像素判断一下就可以了

需要注意的是,每个字母之间有空格,所以方便输入就用gets

【时间复杂度&&优化】

O(nm)

题目链接→Codeforces Problem 707A Brain's Photos



 Source Code

/*Sherlock and Watson and Adler*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#define eps 1e-9
#define LL long long
#define PI acos(-1.0)
#define bitnum(a) __builtin_popcount(a)
using namespace std;
const int N = 205;
const int M = 40;
const int inf = 1000000007;
const int mod = 1000000007;
char s

;
int main()
{
int n,m,i,j;
bool flag=true;
scanf("%d%d\n",&n,&m);
for(i=0;i<n;i++)
gets(s[i]);
for(i=0;i<n&&flag;i++)
for(j=0;s[i][j]!='\0'&&flag;j++)
if(s[i][j]=='C'||s[i][j]=='M'||s[i][j]=='Y')
flag=false;
if(flag)
puts("#Black&White");
else
puts("#Color");
return 0;
}


菜鸟成长记
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: