B. Cards

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output: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?

Input

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.

Output

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.

Examples
Input
2
RB
Output
G
Input
3
GRG
Output
BR
Input
5
BBBBB
Output
B
Note

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.

题目链接:http://codeforces.com/contest/626/problem/B

题意:有n张卡片,颜色有B,G,R三种,两张不动颜色的卡片合成一张第三种颜色的卡片,两张相同颜色的卡片合成该颜色的一张卡片。 按照此规则,任意组合,输出最后一张卡片的颜色,输出所有可能。

分析:模拟+规律。

①当n张卡片只有一种颜色,最后一张肯定就是该颜色。

②当n(n>2)张卡片里有两种颜色,A有(n-1)张,B只有1张,那么结果可以为B,C两种颜色。

③当n==2,且有A,B颜色卡片各一张,则最后颜色为C颜色。

④其他情况均有A,B,C这三种颜色。

下面给出AC代码:

错写判断条件,连连被卡数据QAQ!

 #include <bits/stdc++.h>
using namespace std;
inline int read()
{
int x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')
f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
int n;
char s[];
int main()
{
n=read();
cin>>s;
int r=,g=,b=;
for(int i=;i<n;i++)
{
if(s[i]=='R')
r++;
if(s[i]=='G')
g++;
if(s[i]=='B')
b++;
}
if(r>&&g==&&b==)
{
cout<<'R'<<endl;
return ;
}
if(r==&&g>&&b==)
{
cout<<'G'<<endl;
return ;
}
if(r==&&g==&&b>)
{
cout<<'B'<<endl;
return ;
}
if(r==&&g==&&b==)
{
cout<<'R'<<endl;
return ;
}
if(r==&&g==&&b==)
{
cout<<'G'<<endl;
return ;
}
if(r==&&g==&&b==)
{
cout<<'B'<<endl;
return ;
}
if(r>&&g==&&b==)
{
cout<<"BG"<<endl;
return ;
}
if(r>&&g==&&b==)
{
cout<<"BG"<<endl;
return ;
}
if(r==&&g>&&b==)
{
cout<<"BR"<<endl;
return ;
}
if(r==&&g>&&b==)
{
cout<<"BR"<<endl;
return ;
}
if(r==&&g==&&b>)
{
cout<<"GR"<<endl;
return ;
}
if(r==&&g==&&b>)
{
cout<<"GR"<<endl;
return ;
}
if((r>&&g>)||(g>&&b>)||(r>&&b>)||(r>=&&g>=&&b>=))
{
cout<<"BGR"<<endl;
return ;
}
return ;
}

Codeforces 626B Cards(模拟+规律)的更多相关文章

  1. CodeForces 626B Cards

    瞎搞题...凭直觉+猜测写了一发,居然AC了.. #include<cstdio> #include<cstring> #include<cmath> #inclu ...

  2. Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列

    题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...

  3. CodeForces - 1003-B-Binary String Constructing (规律+模拟)

    You are given three integers aa, bb and xx. Your task is to construct a binary string ssof length n= ...

  4. Codeforces 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...

  5. codeforces D. Queue 找规律+递推

    题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...

  6. CF Soldier and Cards (模拟)

    Soldier and Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

  8. CodeForces - 950C Zebras 模拟变脑洞的天秀代码

    题意:给你一个01串,问其是否能拆成若干形如0101010的子串,若能,输出所有子串的0,1 的位置. 题解:一开是暴力,然后瞎找规律, 最后找到一种神奇的线性构造法:扫一遍字符串,若为0就一直竖着往 ...

  9. Codeforces 631C. Report 模拟

    C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

随机推荐

  1. iOS 图片的拉伸,取固定区域显示

    1.图片拉伸合适的尺寸 以及清晰度 UIButton * but =[[UIButton alloc]initWithFrame:CGRectMake(, , , )]; //拉伸 /*UIImage ...

  2. git stash的用法

    使用git stash git stash的使用场景是这样的: 当你正在你的分支下进行开发时,这时候你可能需要切换到你的另一个分支去,你可能要pull新的代码下来,但是你又不想添加无用的commit. ...

  3. Concurrency Is Not Parallelism (Rob pike)

    Rob pike发表过一个有名的演讲<Concurrency is not parallelism>(https://blog.golang.org/concurrency-is-not- ...

  4. css3整理-方便查询使用

    最近详细地研究了CSS3的相关内容,并整理了这个文档,方便以后查询使用,分享给大家. 案例代码大家可以下载参考下:https://gitee.com/LIULIULIU8/CSS3 1.边框属性bor ...

  5. Q:javax.comm 2.0 windows下Eclipse的配置

    @转自http://blog.csdn.net/zhuanghe_xing/article/details/7523744处 要在Windows下,对计算机的串口或并口等进行编程,可以选择使用Java ...

  6. Ajax 原生和jQuery的ajax用法

    https://www.cnblogs.com/jach/p/5709175.html form数据的序列化: $('#submit').click(function(){ $('#form').se ...

  7. ES6(二) Destructuring-变量的解构赋值

    1.解构的含义 允许按照一定的模式,从数组和对象中取值,对变量进行赋值,称为解构. 解构赋值时,只要等号右边的值不是对象,就先将其转换成对象. 本质上,这种写法属于 “模式匹配”,只要两边模式相同,左 ...

  8. margin和padding的区别和用法

    margin和padding的区别和用法 什么是margin.padding? marigin:就是外边距.padding:就是内边距.怎么就容易记住两者呢? 马蓉大家都知道吧,给王宝强带帽子的那位, ...

  9. 单独mybatis得使用

    今天同学说要学习mybatis后来他写了个程序让我看看,我看了一下发现包引错了,他写的是单独的mybatis,引入的却是spring-mybatis,所以会报错. 今天我记录一下单独mybatis的使 ...

  10. Gulp自动化构建工具的简单使用

    相关网站 gulp官方网址:http://gulpjs.com gulp中文网站:http://www.gulpjs.com.cn/ gulp插件地址:http://gulpjs.com/plugin ...