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. Python3 hashlib模块和hmac 模块(加密)

    hashlib 是一个提供了一些流行的hash算法的 Python 标准库.其中所包括的算法有 md5, sha1, sha224, sha256, sha384, sha512等常用算法 MD5加密 ...

  2. ogre3d环境配置 SDK安装配置及简单事例教程

    ogre3d环境配置 SDK安装配置及简单事例教程 http://www.cr173.com/html/22594_1.html ogre3d环境配置 SDK安装配置及简单事例教程 http://ww ...

  3. [bugfix]copy属性参数将NSMutableArray变为NSArray类型

    问题:NSMutableArray 声明为 copy 属性参数后即使接受NSMutableArray变量依然为NSArray变量 测试: 属性申明为: 1 @property (nonatomic, ...

  4. dos命令连接mysql并且查看编码方式

    打开cmd: 输入:mysql -hlocalhost -uroot -p 然后: show variables like 'char%';

  5. FineReport——JS二次开发(局部刷新)

    在FR中,可以通过在form表单设置多个报表模板,然后通过对某一模板刷新实现局部刷新的功能,在cpt模板中,由于只存在一个模板,所以无法实现局部刷新. 其实,最好的局部刷新办法是自定义一个页面,然后添 ...

  6. Mac 使用自带的Ruby 安装brew

    Homebrew简称brew,OSX上的软件包管理工具,在Mac终端可以通过brew安装.更新.卸载软件. 首先要安装brew,在 mac 中使用finder 搜索 终端(terminal)打开命令行 ...

  7. Codeforces 707C Pythagorean Triples(构造三条边都为整数的直角三角形)

    题目链接:http://codeforces.com/contest/707/problem/C 题目大意:给你一条边,问你能否构造一个包含这条边的直角三角形且该直角三角形三条边都为整数,能则输出另外 ...

  8. LeetCode解题报告—— Jump Game & Merge Intervals & Permutation Sequence

    1. Jump Game Given an array of non-negative integers, you are initially positioned at the first inde ...

  9. Django-form組件補充

    自定义验证规则 方法一: 1 2 3 4 5 6 7 8 9 10 from django.forms import Form   from django.forms import widgets f ...

  10. redis之(二十)redis的总结一

    1 什么是Redis Redis(REmote DIctionary Server,远程数据字典服务器)是开源的内存数据库,常用作缓存或者消息队列. Redis的特点: Redis存在于内存,使用硬盘 ...