Codeforces 626 B. Cards (8VC Venture Cup 2016-Elimination Round)
2 seconds
256 megabytes
standard input
standard output
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.
2
RB
G
3
GRG
BR
5
BBBBB
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.
题意就是两种颜色不同的牌合成一个第三种颜色的牌,两种颜色相同的就合成该颜色的牌,问最后可能的颜色是什么。
要注意一点就是要按字母顺序输出,就是wa在这里了。。。
有以下几种情况:
1.只有一张牌,最后就是这张牌的颜色。
2.两张牌,都是同一种颜色就直接输出了,如果不同就是第三种牌的颜色。
3.多张牌(>2)
1)都是同一种颜色就直接输出了。
2)如果除了一张牌颜色不一样,其他的牌都是一种颜色,最后输出的结果就是这一张牌的颜色和第三种颜色。
3)如果颜色都有或者只有两种颜色,但是每一种颜色的牌数>1,结果就是三种颜色都输出。
要按字母顺序输出!!!
代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
char str[250];
int n,b,r,g;
while(~scanf("%d",&n)){
scanf("%s",&str);
b=0;r=0;g=0;
if(n==1) printf("%c\n",str[0]);
else if(n==2){
if(str[0]=='B'&&str[1]=='B') printf("B\n");
else if(str[0]=='G'&&str[1]=='G') printf("G\n");
else if(str[0]=='R'&&str[1]=='R') printf("R\n");
else{
if((str[0]=='B'||str[0]=='G')&&(str[1]=='B'||str[1]=='G')) printf("R\n");
else if((str[0]=='B'||str[0]=='R')&&(str[1]=='B'||str[1]=='R')) printf("G\n");
else if((str[0]=='G'||str[0]=='R')&&(str[1]=='G'||str[1]=='R')) printf("B\n");
}
}
else{
for(int i=0;i<n;i++){
if(str[i]=='B') b++;
if(str[i]=='G') g++;
if(str[i]=='R') r++;
}
if(b==n) printf("B\n");
else if(r==n) printf("R\n");
else if(g==n) printf("G\n");
else if(b+g==n&&b>g&&g==1) printf("GR\n");
else if(b+g==n&&b<g&&b==1) printf("BR\n");
else if(b+r==n&&b>r&&r==1) printf("GR\n");
else if(b+r==n&&b<r&&b==1) printf("BG\n");
else if(g+r==n&&g>r&&r==1) printf("BR\n");
else if(g+r==n&&g<r&&g==1) printf("BG\n");
else printf("BGR\n");
}
}
return 0;
}
Codeforces 626 B. Cards (8VC Venture Cup 2016-Elimination Round)的更多相关文章
- 8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞
B. Cards 题目连接: http://www.codeforces.com/contest/626/problem/B Description Catherine has a deck of n ...
- codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre
C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...
- Codeforces 8VC Venture Cup 2016 - Elimination Round F. Group Projects 差分DP*****
F. Group Projects There are n students in a class working on group projects. The students will div ...
- 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)
题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...
- 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树
G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...
- 8VC Venture Cup 2016 - Elimination Round F. Group Projects dp
F. Group Projects 题目连接: http://www.codeforces.com/contest/626/problem/F Description There are n stud ...
- 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分
E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...
- 8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力
D. Jerry's Protest 题目连接: http://www.codeforces.com/contest/626/problem/D Description Andrew and Jerr ...
- 8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分
C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...
随机推荐
- 【bzoj4627】[BeiJing2016]回转寿司 离散化+树状数组
题目描述 给出一个长度为n的序列,求所有元素的和在[L,R]范围内的连续子序列的个数. 输入 第一行包含三个整数N,L和R,分别表示寿司盘数,满意度的下限和上限. 第二行包含N个整数Ai,表示小Z对寿 ...
- BZOJ4651 NOI2016网格(割点)
首先显然可以通过孤立角落里的跳蚤使其不连通,所以只要有解答案就不会大于2.同样显然的一点是当且仅当跳蚤数量<=2且连通时无解.做法其实也很显然了:特判无解,若跳蚤不连通输出0,否则看图中是否无割 ...
- c# 以多个字符串分隔字符串数据 分组 分隔 split 正则分组
string str="aaa[##]ccc[##]ddd[##]bb" Regex regex=new Regex("[##]");//以 [##] 分割 s ...
- [CF45G]Prime Problem
题目大意:将$1$到$n(1<n\leqslant6000)$分成若干组数,要求每组数的和均为质数,若存在一种分配方式,输出每个数所在的组的编号,有多组解输出任意一组解,若不存在,输出$-1$ ...
- Linux设置虚拟内存-创建和启用Swap交换区
如果你的服务器的总是报告内存不足,并且时常因为内存不足而引发服务被强制kill的话,在不增加物理内存的情况下,启用swap交换区作为虚拟内存是一个不错的选择,如果是SSD硬盘,正常读写速度都在300M ...
- jquery和ajax,json写法的说明
一: 在ajax中,如果没有用jquery,则如xmlHttpRequest.open("POST", "AjaxServlet", true); (1)如果用 ...
- (转)C/S 与 B/S 区别
感谢:http://www.cnblogs.com/xiaoshuai/archive/2010/05/25/1743741.html C/S结构,即Client/Server(客户机/服务器)结构, ...
- hive的体系架构及安装
1,什么是Hive? Hive是能够用类SQL的方式操作HDFS里面数据一个数据仓库的框架,这个类SQL我们称之为HQL(Hive Query Language) 2,什么是数据仓库? 存放数据的地方 ...
- jvm面试必会基本知识
内存: 堆区 1.new的对象实例 ps:(java堆可以细分为新生代和老年代)(通过-xmx和-xms来实现可扩展) 虚拟机栈 局部变量 本地方法栈 为虚拟机使用的native方法服务 方法区 s ...
- [转]使用 LDAP 组或角色限制访问,包含部分单点登录SSO说明
参考:http://www-01.ibm.com/support/knowledgecenter/api/content/SSEP7J_10.2.2/com.ibm.swg.ba.cognos.crn ...