Codeforces C Voting(队列模拟题)

                                           Voting

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

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

中文版题目:

Alternative Cake Manufacturing(ACM)有n名员工。他们现在就一些非常重要的问题进行投票,世界主要媒体正试图预测投票结果。每个雇员都属于两个部分中的一个:共和党人或复仇者,这两个部分对投票结果应该有相反的意见。投票程序相当复杂:n名雇员中的每一名都发表声明。他们从员工1开始逐一发表声明,并以员工n完成。如果在第i名雇员发表声明的时刻,他不再有权投票,他只是跳过轮到他(并且不再参与投票)。当员工发表声明时,他无能为力或宣布其他员工之一不再有投票权。它允许拒绝投票已经发表声明的人或只等待这样做的人。如果某人被拒绝投票,他将不再参与投票直到最后。当所有员工完成他们的陈述时,程序重复:再次,每个员工从1开始,并以n结束仍然有资格投票的人做出陈述。该流程重复进行,直到只有一名员工有资格投票,并确定整个投票的结果。当然,他投票支持适合他的分数的决定。您知道员工将要投票的订单以及他们的行为最佳(并且他们也知道订单以及谁属于哪个部分)。预测投票结果。输入输入的第一行包含一个整数n(1≤n≤200000) - 员工人数。下一行包含n个字符。如果第i个雇员来自deublicublicans分数,那么第i个字符是'D',如果他来自reocrats,则是'R'。输出打印'D'如果投票结果适合于共和党人,'R'如果民主党人将获胜。示例输入5 DDRRR输出D输入6 DDRRRR输出R注意考虑第一个样本的投票场景之一:员工1拒绝员工5投票。员工2拒绝员工3投票。员工3无权投票并跳过轮到他(员工2拒绝了他)。员工4否认员工2投票。员工5无权投票并跳过轮到他(员工1拒绝了他)。员工1否认员工4.只有员工1现在才有投票权,因此投票以终结者的胜利结束。

题意:

这道题目是先让我们输入n个D或者R,然后开始模拟,D和R分别按照顺序可以使对方出局和禁言,然后留下的最后一个就是胜者

思路:

只要用队列模拟出比赛过程就可以了。

代码:

#include<bits/stdc++.h>
using namespace std;
int n;//表示D和R的数量
char a[200005];//用来存储输进来的数据
queue<int> d,r;//定义两个队列分别用来存放D和R的 
int main()
{
	while(~scanf("%d",&n))//输入D和R总数量 
	{
		scanf("%s",a);//输入整个字符 
		for(int i=0;i<n;i++)
		{
			if(a[i]=='D') d.push(i);//分开两个队列 
			else r.push(i);
		}
		while(!r.empty()&&!d.empty())//该题的核心代码 
		{
			int R=r.front();//如果没有被吃掉的话,就将这个字母移到对列的末尾 
			int D=d.front();
			if(R<D)
			{
				r.pop();
				d.pop();
				r.push(n+R);
			}
			else
			{
				d.pop();
				r.pop();
				d.push(n+D);
			}
		}
		if(!r.empty()) printf("R\n");//如果r队列有剩余的话,那么就说明R赢了 
		else printf("D\n");
	}
	return 0;
} 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值