Codeforces 626B Cards(规律)
来源:互联网 发布:android sdk源码下载 编辑:程序博客网 时间:2024/05/17 22:46
Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color;
- take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color.
She repeats this process until there is only one card left. What are the possible colors for the final card?
The first line of the input contains a single integer n (1 ≤ n ≤ 200) — the total number of cards.
The next line contains a string s of length n — the colors of the cards. s contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.
Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.
2RB
G
3GRG
BR
5BBBBB
B
In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.
In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card.
In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.
题意:有n张卡片,颜色有B,G,R三种,两张不动颜色的卡片合成一张第三种颜色的卡片,两张相同颜色的卡片合成该颜色的一张卡片。 按照此规则,任意组合,输出最后一张卡片的颜色,输出所有可能。
题解:规律题。①当n张卡片只有一种颜色,最后一张肯定就是该颜色。
②当n(n>2)张卡片里有两种颜色,A有(n-1)张,B只有1张,那么结果可以为B,C两种颜色。
③当n==2,且有A,B颜色卡片各一张,则最后颜色为C颜色。
④其他情况均有A,B,C这三种颜色。
代码如下(看了外国菊苣写的,我写的码真渣):
#include<cstdio>#include<cstring>char str[210];int main(){int n,r,b,g,i;while(scanf("%d",&n)!=EOF){scanf("%s",str);r=0; b=0; g=0;for(i=0;i<n;++i){if(str[i]=='R')r++;if(str[i]=='G')g++;if(str[i]=='B')b++;}if(r>0&&g==0&&b==0)printf("R\n");else if(r==0&&g>0&&b==0)printf("G\n");else if(r==0&&g==0&&b>0)printf("B\n");else if(r==0&&g==1&&b==1)printf("R\n");else if(r==1&&g==0&&b==1)printf("G\n");else if(r==1&&g==1&&b==0)printf("B\n");else{if(r>1){if(g==1&&b==0)printf("BG\n");else if(g==0&&b==1)printf("BG\n");else printf("BGR\n");}else if(g>1){if(r==1&&b==0)printf("BR\n");else if(r==0&&b==1)printf("BR\n");elseprintf("BGR\n");}else if(b>1){if(g==1&&r==0)printf("GR\n");else if(g==0&&r==1)printf("GR\n");elseprintf("BGR\n");}elseprintf("BGR\n");}}return 0;}
- Codeforces 626B Cards(规律)
- CodeForces-626B-Cards
- CodeForces 626B-Cards【DFS】
- CodeForces 626B:Cards【模拟】
- Codeforces 626B Cards 【BFS or 讨论】
- CodeForces 626 B. Cards(水~)
- CodeForces - 626B Cards (全排列&模拟)
- Codeforces--626B--Cards(模拟)
- CodeForces 626B Cards(数学思维)
- codeforces-626-B. Cards(简单模拟)
- Codeforces Round #364(Div. 2) A. Cards【模拟】 && B. Cells Not Under Attack【SET/规律】
- codeforces 830B. Cards Sorting
- Codeforces B. Cards Sorting 【瞎搞】
- 626B-Cards
- CF 626 B. Cards
- CodeForces 204B - Little Elephant and Cards
- codeforces 204B- Little Elephant and Cards
- Codeforces 204B Little Elephant and Cards
- java中字符串的替换
- 自定义测试执行器
- smarty文件引用
- React-Native学习指南
- 程序错误记录
- Codeforces 626B Cards(规律)
- [MyBatis日记](5)结果集映射ResultMaps
- 百度母婴技术团队—基于Reactjs实现webapp #1
- 软件,互联网,游戏——我的技术之路
- Android一步步深入理解View(一):LayoutInflater的使用和原理分析
- 触控推出新的编辑器Cocos Creator等四个引擎商业化新进展
- Elastic Search 5 分钟教程
- 算法提高 日期计算 蓝桥杯java详解
- thinkpad t440p 如何默认F1~F12按键