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 with n 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
题意:一组字符串中有DR两种字符
按顺序执行一种规则 D可以删除任意位置上的R字符 (R同理) 往复循环
问最后剩下的是什么字符
直接用队列模拟 比较DR位序的大小
 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string.h>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const double PI=acos(-1.0);
const double eps=0.0000000001;
const ll mod=;
const int N=+;
char str[N];
int sum1[N];
int sum2[N];
int n;
queue<int>R,D;
int main(){
while(scanf("%d",&n)!=EOF){
scanf("%s",str+);
while(!D.empty())D.pop();
while(!R.empty())R.pop();
for(int i=;i<=n;i++){
if(str[i]=='D')D.push(i);
else{
R.push(i);
}
}
while(D.empty()==&&R.empty()==){
int x=D.front();
int y=R.front();
if(x<y){
R.pop();
D.pop();
D.push(x+n);
}
else{
D.pop();
R.pop();
R.push(y+n);
}
}
if(D.empty()==){
cout<<"D"<<endl;
}
else{
cout<<"R"<<endl;
}
}
}
												

CodeForces - 749C Voting的更多相关文章

  1. Codeforces 749C. Voting 模拟题

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

  2. Voting CodeForces - 749C

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

  3. Codeforces 749C:Voting(暴力模拟)

    http://codeforces.com/problemset/problem/749/C 题意:有n个人投票,分为 D 和 R 两派,从1~n的顺序投票,轮到某人投票的时候,他可以将对方的一个人K ...

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

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

  5. Codeforces 1251E Voting

    E2. Voting (Hard Version) 题意: 有n个人, 你想让他们都给你投票. 你可以选择花费pi收买第i个人, 或者如果有mi个人已经给你投票了, 那么第i个人会自动给你投票. 不妨 ...

  6. codeforces#1251E2. Voting (Hard Version)(贪心)

    题目链接: http://codeforces.com/contest/1251/problem/E2 题意: 主角需要获得n个人的投票 有两种方式让某个人投票 1,已经投票的人数大于m 2,花p枚硬 ...

  7. Codeforces 749C【模拟】

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

  8. codeforces 637A A. Voting for Photos(水题)

    题目链接: A. Voting for Photos time limit per test 1 second memory limit per test 256 megabytes input st ...

  9. Codeforces Round #388 (Div. 2) C. Voting

    题意:有n个人,每个人要么是属于D派要么就是R派的.从编号1开始按顺序,每个人都有一次机会可以剔除其他任何一个人(被剔除的人就不在序列中也就失去了剔除其他人的机会了):当轮完一遍后就再次从头从仅存的人 ...

随机推荐

  1. Gradle的属性Property设置与调用

    Gradle在默认情况下已经为Project定义了很多Property: project:Project本身 name:Project的名字 path:Project的绝对路径 description ...

  2. (原创)如何对APP服务端进行压力测试

    版权声明:本文为原创文章,转载请先联系并标明出处 APP性能测试分为客户端性能测试和服务端性能测试,客户端的性能测试主要是针对启动快慢.耗电量.耗流量.内存使用等指标进行评估,目前主流的APP客户端性 ...

  3. 在Windows下安装Elasticsearch5.0

    1.准备工作 安装和配置Java环境 2.下载 地址:https://www.elastic.co/downloads/elasticsearch 老版本:https://www.elastic.co ...

  4. WPF在win7运行时报'Initialization of 'System.Windows.Setter' threw an exception.'

    写的一个WPF程序,在win10运行好好的,在win7就报'Initialization of 'System.Windows.Setter' threw an exception.' 原来是xaml ...

  5. VS2015编译ffmpeg的问题解决

    刚装了vs2015,打开一些ffmpeg项目,发现不能编译通过,包括stdio.h都无法找到,可能是vs2015的bug吧. 现在记录一下解决方法: 我的目录是这样定义的: C:\Program Fi ...

  6. 多目标跟踪笔记一:Finding the Best Set of K Paths Through a Trellis With Application to Multitarget Tracking

    Abstract 本文提出一种寻找K最优路径的方法. k最优路径的定义:1.the sum of the metrics of all k paths in the set is minimized. ...

  7. Oracle ASM注意事项

    ASM是负载均衡的存储策略,加新磁盘会将其它盘数据平均迁移到新磁盘,删除磁盘会将删除磁盘数据平均写回其它磁盘 1.同一磁盘组如果是在raid上,划分的磁盘越少越好,磁盘组分布在不同raid上性能好: ...

  8. BZOJ 4285 使者 (CDQ分治+dfs序)

    题目传送门 题目大意:给你一棵树,有三种操作,在两个点之间连一个传送门,拆毁一个已有的传送门,询问两个点之间的合法路径数量.一条合法路径满足 1.经过且仅经过一个传送门 2.不经过起点终点简单路径上的 ...

  9. LINUX应用开发(面试)

    LINUX应用开发工程师职位 本试卷从考试酷examcoo网站导出,文件格式为mht,请用WORD/WPS打开,并另存为doc/docx格式后再使用 说明:应用开发可考察的点非常多,关键的还是C语言和 ...

  10. play snake on windows

    今天和人吃晚饭突然想起来 之前西佳佳老师说小学期会要求两星期撸一个小游戏 有人已经撸完一个俄罗斯方块了... 菜逼我决定从最简单的贪吃蛇玩起... 我是直接参考的这个博客 算是相当简单而且很Low的实 ...