Codeforces Problem 707A Brain's Photos(水题)
2016-08-21 10:23
351 查看
此文章可以使用目录功能哟↑(点击上方[+])
比赛链接→Codeforces Round #368 (Div. 2)
Accept: 0 Submit: 0
Time Limit: 2 seconds Memory Limit : 256 megabytes
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.
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'.
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.
2 2
C M
Y Y
3 2
W W
W W
B B
1 1
W
#Color
#Black&White
#Black&White
解题思路:
【题意】
给你一张n*m像素大小的照片
每个像素点有一种颜色,用字母表示
'C'表示青色
'M'表示紫红色
'Y'表示黄色
'W'表示白色
'G'表示灰色
'B'表示黑色
问该照片是黑白照(只包含白色、灰色、黑色三种颜色,即只包含字母'W'、'G'、'B')还是彩色照
【类型】
implementation
【分析】
照片是黑白照,还是彩色照,取决于是否有除了黑白灰三种以外的其他颜色,也就是是否会有'C'、'M'、'Y'三种颜色出现,如果出现了,就是彩色照;否则就是黑白照,我们只需要枚举每个像素判断一下就可以了
需要注意的是,每个字母之间有空格,所以方便输入就用gets
【时间复杂度&&优化】
O(nm)
题目链接→Codeforces Problem 707A Brain's Photos
菜鸟成长记
比赛链接→Codeforces Round #368 (Div. 2)
Codeforces Problem 707A Brain's Photos
Accept: 0 Submit: 0Time 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 2C 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; }
菜鸟成长记
相关文章推荐
- Codeforces Gym 100610 Problem E. Explicit Formula 水题
- Codeforces Round #356 (Div. 2) B. Bear and Finding Criminal 水题
- Problem F CodeForces 16E
- Educational Codeforces Round 13 B. The Same Calendar 水题
- 【Educational Codeforces Round 6A】【水题】Professor GukiZ's Robot 曼哈顿距离
- 并查集Codeforces Round #134 (Div. 1), problem: (A) Ice Skating
- Codeforces Round #360 (Div. 2) B Lovely Palindromes(水题)
- Codeforces Round #400 (Div. 1 + Div. 2, combined)D. The Door Problem【2-sat Tarjan+思维建图】
- Codeforces Round #400 D. The Door Problem(2-sat)
- Educational Codeforces Round 34 div2 Hungry Student Problem 简单dfs
- Codeforces Problem 499B. Lecture
- Codeforces Round #430(Div.2)Problem C Ilya And The Tree(DFS)
- Codeforces Round #228 (Div. 2), problem: (A) Fox and Number Game
- Codeforces Round #185 (Div. 2) A. Whose sentence is it? 水题
- 【Codeforces Round 363 (Div 2) B】【水题 行列计数】One Bomb 炸弹人爆破游戏
- Educational Codeforces Round 14 B. s-palindrome 水题
- 【Codeforces Round 276 (Div 2)B】【水题】Valuable Resources 最小正方形包含所有点
- 【Codeforces Round 335 (Div 2) A】【水题】Magic Spheres 三种类型物品兑换比例2:1.cpp
- Codeforces Problem 710A King Moves(implementation)
- Codeforces Problem 710C Magic Odd Square