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 ...
随机推荐
- JVM致命错误日志(hs_err_pid.log)分析
当jvm出现致命错误时,会生成一个错误文件 hs_err_pid<pid>.log,其中包括了导致jvm crash的重要信息,可以通过分析该文件定位到导致crash的根源,从而改善以保证 ...
- Python 爬虫常用模块
1. fake_useragent #pip install fake_useragent requests 2.图展示 pip install pyecharts pip install pyech ...
- Genomic signatures of evolutionary transitions from solitary to group living(独居到社会性的转变)
1.摘要 群居性的进化是进化的主要过渡之一,但其背后的基因组变化是未知的.我们比较了10种蜜蜂的基因组,它们的社会复杂性各不相同,代表了社会进化中的多种独立过渡,并报告了三项主要发现. 第一,许多重要 ...
- java工程师基础笔试题(一)
一.选择和填空 (不定项哦!) 1,如下是一份文件名为Test2.java的源文件,请问,编译该文件之后会生成几份字节码文件 class Test{ class Inner{} static cla ...
- Java(8)中List的遍历方式
============Java8之前的方式==========Map<String, Integer> items = new HashMap<>();items.put(& ...
- clearfix原理
[clearfix原理] .clearfix:after { <----在类名为“clearfix”的元素内最后面加入内容: content: "."; <----内容 ...
- SpringBoot点滴(1)
spring boot 注意事项 1.项目启动的主类,放置位置在所有类的外层与controller,dao,service,util,entity同层,SpringBoot会自动扫描@SpringBo ...
- python网络编程之开启进程的方式
标签(空格分隔): 开启进程的方式 multiprocessing模块介绍: python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu_count()查看),在pyth ...
- Python 面向对象基础(类、实例、方法、属性封装)
python是面向对象语言,一切皆对象. 面向过程: 变量和函数. “散落” 在文件的各个位置,甚至是不同文件中.看不出变量与函数的相关性,非常不利于维护,设计模式不清晰. 经常导致程序员,忘记某个变 ...
- WDlinux 修改后台默认8080端口的方法
修改8080端口正确方法 新版本: 方法一: apache sed -i 's/8080/8088/' /www/wdlinux/wdapache/conf/httpd.conf 然后记得修改防火墙i ...