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 ...
随机推荐
- OC学习11——循环引用与@class
转载自 OC学习篇之---@class关键字的作用以及#include和#import的区别 一.#import和#include的区别 当我们在代码中使用两次#include的时候会报错:因为#in ...
- Python 集体智慧编程PDF
集体智慧编程PDF 1.图书思维导图http://www.pythoner.com/183.html p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12. ...
- 视觉SLAM的数学表达
相机是在某些时刻采集数据的,所以只关心这些时刻的位置和地图. 就把这一段时间的运动变成了李三时刻 t=1,2,...K当中发生的事情. 在这些事可,x表示机器自身的位置. x1,x2,x3,x4... ...
- bzoj 3718: [PA2014]Parking
Description 你的老板命令你将停车场里的车移动成他想要的样子. 停车场是一个长条矩形,宽度为w.我们以其左下角顶点为原点,坐标轴平行于矩形的边,建立直角坐标系.停车场很长,我们可以认为它一直 ...
- css清除浮动主要方法
1.浮动元素尾部添加空div标签,设置css为clear:both: 缺点:如果页面浮动布局多,则需要添加较多div: 2.父级元素定义伪类:after和zoom:1: .father:after{d ...
- 我是如何确认线上CLOSE_WAIT产生的原因及如何解决的。
1.阐述 内部架构:Tomcat应用程序---> nginx ---> 其他Tomcat应用程序,内部Tomcat应用通过nginx调用其他应用. HTTP插件:HttpClient 4. ...
- Activemq集群搭建
集群搭建 一:静态网络集群 1.简介 当ActiveMQ面对大量消息存储和大量Client交互时,性能消耗将会达到单个broker极限,此时我们需要对ActiveMQ进行水平扩展.ActiveMQ ...
- NumPy学习笔记 二
NumPy学习笔记 二 <NumPy学习笔记>系列将记录学习NumPy过程中的动手笔记,前期的参考书是<Python数据分析基础教程 NumPy学习指南>第二版.<数学分 ...
- Java的演化-Java8实战笔记
一个语言要想一直有活力,它也需要跟随着时代的变化去进步,Java作为一个古老的语言,它其实有太多的历史包袱,在改变的过程中需要考虑很多,但是它也在慢慢的演变,巩固自己的城墙,不让自己被遗忘在历史中(不 ...
- Centos 7 防火墙firewalld命令
今天自己在Hyper-v下搭建三台Linux服务器集群,用于学习ELKstack(即大数据日志解决技术栈Elasticsearch,Logstash,Kibana的简称),下载的Linux版本为cen ...