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 ...
随机推荐
- 【python】python获取当前日期前后N天或N月的日期
# -*- coding: utf- -*- '''获取当前日期前后N天或N月的日期''' from time import strftime, localtime from datetime imp ...
- jquery中ajax的使用(java)
AJAX方式 js:界面 var prjContextPath='<%=request.getContextPath()%>'; $(document).ready(function() ...
- 前端工程师必须要知道的SEO技巧(1):rel=nofollow的使用
前提:最近我在找工作,想面试一些关于前端的工作,被问到了一些关于SEO优化的问题.我深深的感觉我所回答的太过于表面,没有深入.所以,又把SEO的内容看了一遍.自己总结如下:有的是看的其他博友的贴子,发 ...
- 【翻译】为什么Java中的String不可变
笔主前言: 众所周知,String是Java的JDK中最重要的基础类之一,在笔主心中的地位已经等同于int.boolean等基础数据类型,是超越了一般Object引用类型的高端大气上档次的存在. 但是 ...
- js金额转大写数字
//金额转大写数字 const intToChinese = money => { //汉字的数字 let cnNums = new Array('零', '壹', '贰', '叁', '肆', ...
- taotao前台页面显示登录用户名的处理
思路: 在每个页面上都引入一个 jsp,这个 jsp 可以是页面的头 head 或者脚 footer.jsp 然后在这个 jsp 中引入 一个 js,这个 js 中 有个 随页面加载 而执行的 方法, ...
- taotao用户登录springMVC拦截器的实现
在springMVC中写拦截器,只需要两步: 一.写 java 拦截器类,实现 interceptor 拦截器接口. 二.在 springMVC 的xml配置文件中,配置我们创建的拦截器对象及其拦截目 ...
- 【可持久化线段树?!】rope史上最全详解
https://www.luogu.org/problemnew/show/P3919 看到上面链接中的题时,我在学会可持久化线段树的同时,第一次学会了一个非常屌(cai)的STL大法——rope!! ...
- Codeforces Round #538 (Div. 2) (A-E题解)
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
- mysql修改表中某个字段的默认值
Mysql中用SQL增加.删除字段,修改字段名.字段类型.注释,调整字段顺序总结 在网站重构中,通常会进行数据结构的修改,所以添加,删除,增加mysql表的字段是难免的,有时为了方便,还会增加修改 ...