您的位置:首页 > 其它

Codeforces 626B Cards(规律)

2016-02-15 00:19 381 查看
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.

题意:有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");
				else
					printf("BGR\n");
			}
			else if(b>1)
			{
				if(g==1&&r==0)
					printf("GR\n");
				else if(g==0&&r==1)
					printf("GR\n");
				else
					printf("BGR\n");
			}
			else
				printf("BGR\n");
		}
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: