C. Voting
time limit per test:

1 second

memory limit per test:

256 megabytes

input:

standard input

output:

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:

  1. 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).
  2. 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.
  3. 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.
  4. 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.

Input

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.

Output

Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.

Examples
input
5
DDRRR
output
D
input
6
DDRRRR
output
R
Note

Consider one of the voting scenarios for the first sample:

  1. Employee 1 denies employee 5 to vote.
  2. Employee 2 denies employee 3 to vote.
  3. Employee 3 has no right to vote and skips his turn (he was denied by employee 2).
  4. Employee 4 denies employee 2 to vote.
  5. Employee 5 has no right to vote and skips his turn (he was denied by employee 1).
  6. Employee 1 denies employee 4.
  7. 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 模拟题的更多相关文章

  1. Voting CodeForces - 749C (set,模拟)

    大意: n个人, 两个党派, 轮流投票, 两种操作(1)ban掉一个人 (2)投票, 每轮一个未被ban的人可以进行一次操作(1)或操作(2), 求最终哪个党派得票最多. 显然先ban人会更优, 所以 ...

  2. CodeForces - 749C Voting

    C. Voting time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  3. CodeForces - 344A Magnets (模拟题)

    CodeForces - 344A id=46664" style="color:blue; text-decoration:none">Magnets Time ...

  4. Codeforces 749C【模拟】

    FST的时候好像挂了挺多人的~ 其实思路没啥难的,就是更好地理解题意吧,1到n一直循环,直到没有人能vote,一个人能vote也能叉掉一个人,一个人被叉就不能vote,判谁赢. 其实我管vote干嘛, ...

  5. Voting CodeForces - 749C

    有点意思的题 Voting CodeForces - 749C 题意:有n个人投票,每次按照第1个人~第n个人的顺序发言,如果到某个人发言时他已经被禁止发言就跳过,每个人发言时可以禁止另一个人发言或什 ...

  6. Codeforces Gym 100269B Ballot Analyzing Device 模拟题

    Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...

  7. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  8. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  9. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

随机推荐

  1. 前端路由两种模式:hash、history

    随着 ajax 的使用越来越广泛,前端的页面逻辑开始变得越来越复杂,特别是spa的兴起,前端路由系统随之开始流行. 从用户的角度看,前端路由主要实现了两个功能(使用ajax更新页面状态的情况下): 记 ...

  2. java aop的理解

    https://www.cnblogs.com/mafly/p/SpringAOP.html

  3. Spring AOP @Aspect

    spring提供了两个核心功能,一个是IoC(控制反转),另外一个便是Aop(面向切面编程),IoC有助于应用对象之间的解耦,AOP则可以实现横切关注点(如日志.安全.缓存和事务管理)与他们所影响的对 ...

  4. springcloud eureka.instance

    1.在springcloud中服务的 Instance ID 默认值是: ${spring.cloud.client.hostname}:${spring.application.name}:${sp ...

  5. 2.4、CDH 搭建Hadoop在安装(Cloudera Software安装和配置MySQL)

    为Cloudera Software安装和配置MySQL 要使用MySQL数据库,请按照以下过程操作.有关MySQL数据库兼容版本的信息,请参阅CDH和Cloudera Manager支持的数据库. ...

  6. Node KeyNote

    [Node KeyNote] 1.实际上,.node文件在windows下它是一个.dll文件,在*nix下则是一个.so文件. 2.默认变量 function(exports, require, m ...

  7. Application类

    using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; usin ...

  8. 根据23423条件,截取字段‘abdecsdsadsadsad’,以ab/dec/sdsa/ds/ads 输出

    create or replace procedure p_getString ( p_finalString out varchar2, p_rulestring in number, p_sour ...

  9. day17 正则表达式 re模块和hashlib模块

    今日内容 1. re&正则表达式(*****) 注:不要将自定义文件命名为re import re re.findall(正则表达式,被匹配的字符串) 拿着正则表达式去字符串中找,返回一个列表 ...

  10. MyEclipse2014安装aptana插件

    1. 2. aptana插件下载地址 链接: https://pan.baidu.com/s/1sloiAK1 密码: a1nh 3. 4. 确认是否安装成功