Time Limit: 2000MS |
| Memory Limit: 262144KB |
| 64bit IO Format: %I64d & %I64u |
Description Catherine has a deck of n
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. Sample Input Input 2RB Output G Input 3GRG Output BR Input 5BBBBB Output B Hint 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个气球,这n个气球有三种颜色,蓝色(B),绿色(G),红色(R),现在玩一个游戏,每次从n个气球中拿出来两个,如果这两个气球颜色不同,那么这两个气球可以合并成一个第三种颜色的气球,如果这两个气球颜色相同,那么这两个气球可以合并成一个同种颜色的气球,问这样一直合并,直到最后一个。问最后能合并出哪几种颜色的气球。 //思路: 先将n个颜色不同的气球的颜色转换成数字,并将其存在一个数组a中,对a数组进行全排列,并对每一种情况进行合并,直到最后。(当合并出来的气球颜色已经等于3时,直接结束,节省时间,因为总共就3 种颜色)。
//HAIT: 首先得说一下输出格式,有的输入会对应多种输出,但要输出按字母升序排列(WA了3次)。。。 另外用我的思路写有一个bug,那就是当输入为(4 BGBG)时,我的输出是BG,但答案应该是BGR,在这块WA了8次。。。但加了一个特殊判断就过了^_^(在下面代码中会标注)。。。
|