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 ...
随机推荐
- 2018面向对象程序设计(Java)第15周学习指导及要求
2018面向对象程序设计(Java)第15周学习指导及要求 (2018.12.6-2018.12.9) 学习目标 (1) 掌握Java应用程序打包操作: (2) 了解应用程序存储配置信息的两种方法 ...
- 预览InputFile
[预览InputFile] 通过input的files属性,可以取到选择的File对象,通过FileReader可以将File对象读取出来. <body> <input type=& ...
- Pushlet实现后台信息推送(二)
上一篇日志利用推送源周期性地向订阅了某一事件的所有网页端推送信息,但怎么实现向特定的某一个用户推送信息呢,想象一个网络聊天室,怎么向单独的一个好友私聊呢.问题的关键就是那个SessionID,Push ...
- 关于解决java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoader问题
解决方案: 其实是你的jar文件没有同步发布到自己项目的lib目录中 (如果是用Maven进行构建的话) 可以试试 下面的办法 –rebuild下project就可以了 项目点击右键 点击 Prope ...
- KNN算法应用
import numpy as np# 运算符模块,这里主要用来排序 import operator import matplotlib.pylab as plt def create_dataset ...
- HDU-1459.非常可乐(BFS )
这道题TLE了很多次,原来一直以为将数字化为最简可以让运算更快,但是去了简化之后才发现,真正耗时的就是化简....还和队友学到了用状态少直接数组模拟刚就能过... 本题大意:给出可乐的体积v1,给出两 ...
- Evaluate Reverse Polish Notation (STRING-TYPE CONVERTION)
Question Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators a ...
- javascript简单的滑动效果
利用setInterval实现简单的滑动效果 <!DOCTYPE html> <html lang="en"> <head> <meta ...
- h5外部浏览器直接调起app
1. 安卓端: 其中,scheme必须是小写的,同时要求H5必须是“<a href="appback://">启动应用程序</a> ” 2. h5端完整示例 ...
- ABAP开发需要养成的习惯—处理规范,日期,sort,改结构
sELECT select之后不要急着处理,最多用下sort还有delete adjacent,不用sy-subrc判断之后loop操作,要注意处理逻辑. sort一个好处是为了后面read tabl ...