Codeforces 626B Cards(模拟+规律)
B. Cards
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?
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.
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.
2
RB
G
3
GRG
BR
5
BBBBB
B
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代码:

错写判断条件,连连被卡数据QAQ!
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
int x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')
f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
int n;
char s[];
int main()
{
n=read();
cin>>s;
int r=,g=,b=;
for(int i=;i<n;i++)
{
if(s[i]=='R')
r++;
if(s[i]=='G')
g++;
if(s[i]=='B')
b++;
}
if(r>&&g==&&b==)
{
cout<<'R'<<endl;
return ;
}
if(r==&&g>&&b==)
{
cout<<'G'<<endl;
return ;
}
if(r==&&g==&&b>)
{
cout<<'B'<<endl;
return ;
}
if(r==&&g==&&b==)
{
cout<<'R'<<endl;
return ;
}
if(r==&&g==&&b==)
{
cout<<'G'<<endl;
return ;
}
if(r==&&g==&&b==)
{
cout<<'B'<<endl;
return ;
}
if(r>&&g==&&b==)
{
cout<<"BG"<<endl;
return ;
}
if(r>&&g==&&b==)
{
cout<<"BG"<<endl;
return ;
}
if(r==&&g>&&b==)
{
cout<<"BR"<<endl;
return ;
}
if(r==&&g>&&b==)
{
cout<<"BR"<<endl;
return ;
}
if(r==&&g==&&b>)
{
cout<<"GR"<<endl;
return ;
}
if(r==&&g==&&b>)
{
cout<<"GR"<<endl;
return ;
}
if((r>&&g>)||(g>&&b>)||(r>&&b>)||(r>=&&g>=&&b>=))
{
cout<<"BGR"<<endl;
return ;
}
return ;
}
Codeforces 626B Cards(模拟+规律)的更多相关文章
- CodeForces 626B Cards
瞎搞题...凭直觉+猜测写了一发,居然AC了.. #include<cstdio> #include<cstring> #include<cmath> #inclu ...
- Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列
题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...
- CodeForces - 1003-B-Binary String Constructing (规律+模拟)
You are given three integers aa, bb and xx. Your task is to construct a binary string ssof length n= ...
- Codeforces 389B(十字模拟)
Fox and Cross Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submi ...
- codeforces D. Queue 找规律+递推
题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...
- CF Soldier and Cards (模拟)
Soldier and Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- codeforces 591B Rebranding (模拟)
Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...
- CodeForces - 950C Zebras 模拟变脑洞的天秀代码
题意:给你一个01串,问其是否能拆成若干形如0101010的子串,若能,输出所有子串的0,1 的位置. 题解:一开是暴力,然后瞎找规律, 最后找到一种神奇的线性构造法:扫一遍字符串,若为0就一直竖着往 ...
- Codeforces 631C. Report 模拟
C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
随机推荐
- cell上添加倒计时,以及时差问题的解决
原址 http://www.cnblogs.com/zhangmaliang/p/5102518.html 最近项目中用到了tableView的多个cell倒计时系统问题,本觉得很简单的一个事,一做发 ...
- BZOJ4817 SDOI2017 相关分析
4821: [Sdoi2017]相关分析 Time Limit: 10 Sec Memory Limit: 128 MBSec Special Judge Description Frank对天文 ...
- js 变量、作用域和内存问题
基本类型和引用类型 5种基本类型:undefined.null.boolean.number.string 引用类型:由多个值构成的对象 属性 引用类型可以动态添加属性,而基本类型不可以 var p ...
- Docker安装入门 -- 应用镜像
Docker安装入门 -- 应用镜像 WordPress 1.docker build -t csphere/wordpress:4.2 . 2.docker run -d -p 80:80 -- ...
- Python连接webstocker获取消息
简介(脚本都是根据网上资料改写) 此脚本主要是客户觉得webstcket不稳定,所以编辑一个脚本,不停的请求web服务器,当发生错误时,脚本自动退出(). 脚本内容 脚本一 # -*- coding: ...
- c#加密解密源码,md5、des、rsa
从网上找来的代码,顺手改改,用起来更方便. 配置文件 using System; using System.Collections.Generic; using System.Text; using ...
- php实现MySQL读写分离
MySQL读写分离有好几种方式 MySQL中间件 MySQL驱动层 代码控制 关于 中间件 和 驱动层的方式这里不做深究 暂且简单介绍下 如何通过PHP代码来控制MySQL读写分离 我们都知道 &q ...
- 一起学习Hibernate: Hibernate01 —— Hibernate的概述与入门案例
一 Hibernate的介绍 1 让我们从JDBC与替代它的框架Hibernate进行一下对比. 1.1 JDBC的缺点 1) 代码结构繁琐.每次书写sql语句操作数据库都得需要很多步; 2) 是面向 ...
- Bash shell编程的语法知识点(1)
Bash shell脚本编程知识点如下(初学,不全,欢迎讨论补充): shell简介 脚本的简单介绍 变量和引用 算术运算 交互式编程 选择判断 条件测试 循环 函数 shell简介 shell是一种 ...
- async await promise
async 异步函数,以后可能会用得很广. 1.箭头函数: 没有{ }时不写return 也有返回值 2.Promise : 异步神器,很多异步api都是基于Promise 3.new Promise ...