设为首页 收藏本站
查看: 702|回复: 0

[经验分享] Codeforces 626B Cards(模拟+规律)

[复制链接]

尚未签到

发表于 2017-12-9 14:26:28 | 显示全部楼层 |阅读模式
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代码:
   DSC0000.png
  错写判断条件,连连被卡数据QAQ!



  1 #include <bits/stdc++.h>
  2 using namespace std;
  3 inline int read()
  4 {
  5     int x=0,f=1;
  6     char ch=getchar();
  7     while(ch<'0'||ch>'9')
  8     {
  9         if(ch=='-')
10             f=-1;
11         ch=getchar();
12     }
13     while(ch>='0'&&ch<='9')
14     {
15         x=x*10+ch-'0';
16         ch=getchar();
17     }
18     return x*f;
19 }
20 int n;
21 char s[255];
22 int main()
23 {
24     n=read();
25     cin>>s;
26     int r=0,g=0,b=0;
27     for(int i=0;i<n;i++)
28     {
29         if(s=='R')
30             r++;
31         if(s=='G')
32             g++;
33         if(s=='B')
34             b++;
35     }
36     if(r>0&&g==0&&b==0)
37     {
38         cout<<'R'<<endl;
39         return 0;
40     }
41     if(r==0&&g>0&&b==0)
42     {
43         cout<<'G'<<endl;
44         return 0;
45     }
46     if(r==0&&g==0&&b>0)
47     {
48         cout<<'B'<<endl;
49         return 0;
50     }
51     if(r==0&&g==1&&b==1)
52     {
53         cout<<'R'<<endl;
54         return 0;
55     }
56     if(r==1&&g==0&&b==1)
57     {
58         cout<<'G'<<endl;
59         return 0;
60     }
61     if(r==1&&g==1&&b==0)
62     {
63         cout<<'B'<<endl;
64         return 0;
65     }
66     if(r>1&&g==1&&b==0)
67     {
68         cout<<"BG"<<endl;
69         return 0;
70     }
71     if(r>1&&g==0&&b==1)
72     {
73         cout<<"BG"<<endl;
74         return 0;
75     }
76     if(r==1&&g>1&&b==0)
77     {
78         cout<<"BR"<<endl;
79         return 0;
80     }
81     if(r==0&&g>1&&b==1)
82     {
83         cout<<"BR"<<endl;
84         return 0;
85     }
86     if(r==1&&g==0&&b>1)
87     {
88         cout<<"GR"<<endl;
89         return 0;
90     }
91     if(r==0&&g==1&&b>1)
92     {
93         cout<<"GR"<<endl;
94         return 0;
95     }
96     if((r>1&&g>1)||(g>1&&b>1)||(r>1&&b>1)||(r>=1&&g>=1&&b>=1))
97     {
98         cout<<"BGR"<<endl;
99         return 0;
100     }
101     return 0;
102 }
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-422428-1-1.html 上篇帖子: 分享一些有名的交流网站 下篇帖子: windows上安装RabbitMQ
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表