Codeforces 749C. Voting 模拟题
1 second
256 megabytes
standard input
standard output
There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.
Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated:
- Each of n employees makes a statement. They make statements one by one starting from employees 1 and finishing with employee n. If at the moment when it's time for the i-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting).
- When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end.
- When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing withn who are still eligible to vote make their statements.
- The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction.
You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote.
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees.
The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats.
Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.
5
DDRRR
D
6
DDRRRR
R
Consider one of the voting scenarios for the first sample:
- Employee 1 denies employee 5 to vote.
- Employee 2 denies employee 3 to vote.
- Employee 3 has no right to vote and skips his turn (he was denied by employee 2).
- Employee 4 denies employee 2 to vote.
- Employee 5 has no right to vote and skips his turn (he was denied by employee 1).
- Employee 1 denies employee 4.
- Only employee 1 now has the right to vote so the voting ends with the victory of depublicans.
题目链接:http://codeforces.com/problemset/problem/749/C
题意:有n个属于D或R部分的员工进行投票。从1到n依次投票,他们可以给不与自己相同部分的人进行投票,被投票的人将会被剔除出去,不参与投票。一直重复上述步骤,直至不能再进行投票。求最后胜出的部分。
思路:假设D进行投票,投给R,只有投给D后面的R才可能保证D留下的足够多。因为D后面的R会对D进行投票,把D剔除出去。
代码:
#include<bits/stdc++.h>
using namespace std;
const int N = +;
char str[N];
int sign[N];
int main()
{
int n;
memset(str,,sizeof(str));
memset(sign,,sizeof(sign));
scanf("%d %s",&n,str+);
int R1=,R2=,D1=,D2=;
///R1表示剩下的R,R2表示多少位R没有投后面的D;D同理
char flag=;
int cou=;
while(!(R1&&D1))
{
for(int i=; i<=n; i++)
{
if(sign[i]==) continue;
if(cou>=&&flag!=str[i])
{
sign[i]=;
cou--;
continue;
}
if(str[i]=='R')
{
if(D2>=) sign[i]=,D2--;
else R1++,R2++;
}
else
{
if(R2>=) sign[i]=,R2--;
else D1++,D2++;
}
}
if(!(R1&&D1)) break;
cou=R2+D2;
flag=(R2!=)?'R':'D';
D1=D2=R1=R2=;
}
if(R1!=) cout<<"R"<<endl;
else cout<<"D"<<endl;
return ;
}
Codeforces 749C. Voting 模拟题的更多相关文章
- Voting CodeForces - 749C (set,模拟)
大意: n个人, 两个党派, 轮流投票, 两种操作(1)ban掉一个人 (2)投票, 每轮一个未被ban的人可以进行一次操作(1)或操作(2), 求最终哪个党派得票最多. 显然先ban人会更优, 所以 ...
- CodeForces - 749C Voting
C. Voting time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- CodeForces - 344A Magnets (模拟题)
CodeForces - 344A id=46664" style="color:blue; text-decoration:none">Magnets Time ...
- Codeforces 749C【模拟】
FST的时候好像挂了挺多人的~ 其实思路没啥难的,就是更好地理解题意吧,1到n一直循环,直到没有人能vote,一个人能vote也能叉掉一个人,一个人被叉就不能vote,判谁赢. 其实我管vote干嘛, ...
- Voting CodeForces - 749C
有点意思的题 Voting CodeForces - 749C 题意:有n个人投票,每次按照第1个人~第n个人的顺序发言,如果到某个人发言时他已经被禁止发言就跳过,每个人发言时可以禁止另一个人发言或什 ...
- Codeforces Gym 100269B Ballot Analyzing Device 模拟题
Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
随机推荐
- 消息中间件MQ详解及四大MQ比较
一.消息中间件相关知识 1.概述 消息队列已经逐渐成为企业IT系统内部通信的核心手段.它具有低耦合.可靠投递.广播.流量控制.最终一致性等一系列功能,成为异步RPC的主要手段之一.当今市面上有很多主流 ...
- JS----addEventListener()
addEventListener() 用于向指定元素添加事件. 可以向一个元素添加多次事件或者多次不同事件,后面的事件是不会覆盖前面的. 语法: element.addEventListener(ev ...
- laravel 自定义常量的方法
注意:laravel版本为5.1 第一种方法 在本地可以用 我上传到服务器发现用不了 有待解决 第二种方法 在本地可以用 上传服务器后 要把 constants.php 文件权限改为 755 ...
- PHPWAMP集成环境配置ssl证书
和apache配置ssl证书流程一样, LoadModule socache_shmcb_module modules/mod_socache_shmcb.so LoadModule ssl_modu ...
- Hadoop特点
一:HDFS 1.HDFS上传数据,会将文件切分成指定大小的数据块,并以多副本的数据块存储在机器上. 2. part0是指 副本有2个而且1,2有两个副本 二.YARN 1.负责整个集群的管理和调度 ...
- delete[] p与 delete p
基本类型的对象没有析构函数,所以回收基本类型组成的数组空间用 delete 和 delete[] 都是应该可以的:但是对于类对象数组,只能用 delete[].对于 new 的单个对象,只能用 del ...
- f5 2017.09.03故障
1.下午14点50左右有同事反应epm等系统登录有问题.自测登录也是有同样的报错. 2.测试发现内部IP直接访问正常,但是访问f5的vip的方式访问不了.此时oa.邮件等系统也开始有同事发现故障. 3 ...
- Compile、Make和Build的区别
针对Java的开发工具,一般都有Compile.Make和Build三个菜单项,完成的功能的都差不多,但是又有区别. 编译,是将源代码转换为可执行代码的过程.编译需要指定源文件和编译输出的文件路径 ...
- 细说GIT分布式版本控制器
一.Git介绍 Git是目前世界上最先进的分布式版本控制器.Svn CVS 版本控制器:就是用来追溯自己书写的代码的记录信息.好处:可以非常方便的记录何时何地何人操作了哪些代码. 什么是分布式版本控制 ...
- 37-Arrays.sort() 由大到小排序 和 对象数组排序
1. 由大到小排序: 2. 对象数组排序: 1. 由大到小排序: 注意:必需是Integer 类型的数组!!! 方法一: import java.util.Arrays; import java.ut ...