B. Cards

题目连接:

http://www.codeforces.com/contest/626/problem/B

Description

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.

Sample Input

2

RB

Sample Output

G

Hint

题意

有三种颜色的牌,现在有两种决策

1.拿出两张不同颜色的牌,可以换取另外一种颜色的牌

2.拿出两张相同颜色的牌,可以得到另外一种颜色的牌

问你最后剩下的牌的颜色的可能性

题解:

我们显然可以一直使用操作2,使得每种颜色的牌至多一张,这时候我们开始判断就好了。

我们最后剩下B的条件是(R>0&&G>0)||(B>0&&R0&&G0)

其他颜色同理,我们把三种颜色都判一判就好了。

但是我们在一开始牌很多的时候,我们可以兑换出我们一开始没有的颜色,所以这时候,我们瞎搞一下,然后再check。

大概就是这样了。

代码

#include<bits/stdc++.h>
using namespace std; int x[4];
string s;
string ans;
int flag[4];
void check()
{
if(x[1]>0&&x[2]>0)flag[3]++;
if(x[2]>0&&x[3]>0)flag[1]++;
if(x[1]>0&&x[3]>0)flag[2]++;
}
int main()
{
srand(time(NULL));
int n;scanf("%d",&n);
cin>>s;
for(int i=0;i<s.size();i++)
{
if(s[i]=='R')x[1]++;
else if(s[i]=='G')x[2]++;
else x[3]++;
}
if(x[1]==0&&x[2]==0)return puts("B");
if(x[2]==0&&x[3]==0)return puts("R");
if(x[1]==0&&x[3]==0)return puts("G");
check();
for(int i=0;i<10000;i++)
{
int p = rand()%3+1,q = rand()%3+1;
if(p==q)continue;
if(p>q)swap(p,q);
if(x[p]>0&&x[q]>0)
{
if(p==1&&q==2)
{
x[p]--,x[q]--;
x[3]++;
check();
x[p]++,x[q]--;
x[3]--;
}
if(p==1&&q==3)
{
x[p]--,x[q]--;
x[2]++;
check();
x[p]++,x[q]--;
x[2]--;
}
if(p==2&&q==3)
{
x[p]--,x[q]--;
x[1]++;
check();
x[p]++,x[q]--;
x[1]--;
}
}
}
if(flag[3])cout<<"B";
if(flag[2])cout<<"G";
if(flag[1])cout<<"R";
cout<<endl;
}

8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞的更多相关文章

  1. 8VC Venture Cup 2016 - Elimination Round

    在家补补题   模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...

  2. 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 ...

  3. 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)

    题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...

  4. 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 + ...

  5. 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题

    F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...

  6. 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树

    G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...

  7. 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 ...

  8. 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分

    E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...

  9. 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 ...

随机推荐

  1. H264协议(转)

    码率(Bitrate).帧率(FPS).分辨率和清晰度的联系与区别:https://blog.csdn.net/pc9319/article/details/79621352 H.264编码原理以及I ...

  2. Django rest framework + Vue简单示例

    构建vue项目参考这篇文章https://segmentfault.com/a/1190000008049815 一.创建Vue项目 修改源:npm config set registry https ...

  3. make command explaination 編譯命令解釋

    Creating .config file make ARCH=arm CROSS_COMPILE=arm-none-eabi- stm32_defconfig 以上命令是 將變數 ARCH=arm, ...

  4. C#使用Linq To XML读取XML,Linq生成XML,Linq创建带属性或带节点XML

    using System; using System.Linq; using System.Xml.Linq; namespace Sample2 { class Program { static v ...

  5. Oracle简述

    Oracle是甲骨文公司推出的一款大型数据库管理系统.甲骨文公司成立于1977年,总部位于美国加利福尼亚州的红木滩.1989年,Oracle正式进入中国市场:2013年,甲骨文超越 IBM ,成为继 ...

  6. ie6、ie7下overflow失效

    如果父对象有overflow:hidden属性,子对象中的position属性是relative或者absolute, 那么在ie6和ie7下父对象的overflow会失效,解决办法是给父对象加rel ...

  7. Nginx web proxy NFS服务

    1.nginx web 安装 配置 #systemctl stop firewalld #systemctl disabled firewalld #wget -O /etc/yum.repos.d/ ...

  8. Oracle11g常用的命令

    cmd H: cd H:\oracle\product\\Db_1\BIN exp jz/jz file=C:/QS-BF20131017.dmp (备份) imp jz/jz file=C:/BF2 ...

  9. python 几种循环性能测试: while, for, 列表生成式, map等

    直接上代码: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/07/24 16:23 import itertools imp ...

  10. Appscan的第一个测试请求就是提交MAC地址

    GET /AppScan_fingerprint/MAC_ADDRESS_真实的MAC地址.html HTTP/1.0 还好都是合法测试,否则情何以堪...