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是可选 ...
- ThinkPHP5 正则验证中有“|”时提示“规则错误”的解决方案
正则规则中有“|”时,会引起解析错误: 'regex:\d{3,4}[\s,-]?\d{7,8}|1[3,4,5,8]\d[\s,-]?\d{4}[\s,-]?\d{4}' 使用数组语法可以解决: [ ...
- django-1366, "Incorrect string value: '\\xE6\\x88\\x9A\\xE4\\xBC\\x9F...'
今天把之前的一些代码转移到另外一台电脑的时候, python manage.py syncdb 的时候报了 (1366, "Incorrect string value: '\\xE6\\x ...
- LeetCode解题报告—— Permutations & Permutations II & Rotate Image
1. Permutations Given a collection of distinct numbers, return all possible permutations. For exampl ...
- poj 1742(好题,楼天城男人八题,混合背包)
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 33269 Accepted: 11295 Descripti ...
- Longest Substring Without Repeating Characters——经典题
Given a string, find the length of the longest substring without repeating characters. For example, ...
- 【hdoj_1085】Holding Bin-Laden Captive![母函数]
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1085 可以这样理解题意:给出1元,2元和5元的三种硬币若干,每种硬币数量给出,现在可以从所有的硬币中,选出 ...
- 手动安装gcc 4.8.5
# 下载gcc wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz # 解压并进入目录 tar -zxvf gcc-.tar.gz cd ...
- Django学生管理系统添加学生时,报错Not Found: /POST
最近在学习Django,跟着视频写了一个学生系统,主要是增删改查操作,界面丑的一匹 1.url.py from django.contrib import admin from django.urls ...
- Jenkins发布PHP代码
实验环境 10.0.0.12 Jenkins服务器 10.0.0.13 远程服务器 一个远程的公开的git仓库(php代码在这个仓库里) 一.检查插件是否安装并安装插件 在通过Jenkins发布php ...