8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞
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 瞎搞的更多相关文章
- 8VC Venture Cup 2016 - Elimination Round
在家补补题 模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...
- 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 ...
- 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)
题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...
- 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 + ...
- 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题
F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...
- 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树
G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...
- 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 ...
- 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分
E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...
- 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 ...
随机推荐
- 【Python学习笔记】Coursera之PY4E学习笔记——File
1.打开文件 使用handle=open(filename,mode)打开文件.这一函数将会返回一个handle(应该翻译为“柄”吧)用来操控文件,参数filename是一个字符串.参数mode是可选 ...
- c语言简单实现telnet客户端
c语言简单实现telnet客户端 http://blog.csdn.net/haiwenchen/article/details/69944118
- leetcode 之Linked List Cycle(24)
两个思路,一是用哈希表记录每个结点是还被访问过:二是定义两个快.慢指针,如果存在环的话,两个指针必定会在某位结点相遇. bool linkListNode(ListNode *head) { List ...
- Django 批量导入文件
1. 按照xlrd软件 pip3 install xlrd 2. POST提交文件获取数据 方法一:写入硬盘,xlrd读取xlsx文件获取文件数据 def batch_view(self,reques ...
- hdu 3667(最小费用最大流+拆边)
Transportation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- python运行原理/python解释器
先Mark一下这个主题,内容待添加... 参考文章: [1]http://www.cnblogs.com/restran/p/4903056.html [2]https://blog.hakril.n ...
- 183. Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
- Djangp2.x版本报错找不到模版目录下的文件
1.报错内容:django.template.exceptions.TemplateDoesNotExist: index.html 2.解决办法,在settings.py文件中,找到TEMPLATE ...
- Interllij IDEA 使用Git工具
1.git简介 git是目前流行的分布式版本管理系统.它拥有两套版本库,本地库和远程库,在不进行合并和删除之类的操作时这两套版本库互不影响.也因此其近乎所有的操作都是本地执行,所以在断网的情况下任然可 ...
- file '/grub/i386-pc/normal.mod' not found.解决方案
前言: 因为之前装的Ubuntu出了点问题,本想直接清除Ubuntu数据重新装一下,结果蹦出这么个BUG来,揪心,弄了大半天终于弄好了. 废话不多说,直接按教程走吧. GRUB启动: 在grub启动界 ...