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. vue 安装sass扩展

    1.创建一个基于 webpack 模板的新项目 $ vue init webpack myvue 1 2.在当前目录下,安装依赖 $ cd myvue $ npm install 1 2 3.安装sa ...

  2. centos7里面docker不能下载本地源

    报这种错的 编辑这个文件 加上这一段内容 rstart重启,搞定.

  3. 03_java基础(八)之static关键字与代码块

    20\21.static关键字 /** * static关键字 * 1.用static修饰后的方法,称为静态方法. * 2.静态的方法特点,可以使用 类名.方法名称 调用方法 * 3.静态方法只能调用 ...

  4. Oracle VM VirtulBox 安装Ubuntu16.04

    曾经自己在电脑中检索到Ubuntu kylin 16-10.vmdk 后就通过. 这种方式就进行了新建. 后自己从http://www.gaofumei.net/linux-download/783. ...

  5. 关于WPS查看PDF文件操作问题

    自己一直使用WPS打开PDF类的文档,但是使用过程中,存在下面的几个问题: pdf 如何查看当前页码pdf 如何根据目录跳转到指定页WPS 查看pdf 如何跳转到指定页 后来百度后,可以考虑将PDF转 ...

  6. Shader基础(渲染管线)

    Shader原理部分 渲染绘图管线流程:     1.顶点处理(坐标系的转换) 一个模型有自身的方向(前方,上方,右方等)和中心点,既本地坐标系: 将这个模型放到场景当中,通过场景中的世界坐标原点和世 ...

  7. 【Django】关于使用阿里的iconfont

    刚刚从看到课程里老师使用了阿里提供的矢量图标iconfont.cn 我记录一下基本步骤: 1.登录iconfont.cn,搜索图标 2.选中想要的icon点击添加入库,再从右上方点购物车,把icon添 ...

  8. 二:python 对象类型概述

    1,为什么使用内置类型: a)内置对象使程序更容易编写 b)内置对象是扩展的组件 c)内置对象往往比定制的数据结构更加高效 d)内置对象是语言的标准的一部分 2,python  的主要内置对象 对象类 ...

  9. js导出excel:前端当前数据的导出

    网上找的库文件,同样做了修改.在导出的时候,有时候数据第一列和最后一列可能是复选框和操作按钮,这个是我们不需要的,加了这个的过滤 //table2excel.js /* * jQuery table2 ...

  10. POJ-1458.CommonSubsequence.(DP:最长公共子序列裸题)

    本题大意:给出两个字符串,让你求出最长公共子序列的长度并输出. 本题思路:本题是经典的DP问题,由于是两个字符串,那么我们就用一个二维数组来进行区分,用dp[ i ][ j ]来表示在s1和s2中分别 ...