当前位置:   article > 正文

Codeforces C Voting(队列模拟题)_alternative cake manufacturing(acm)有 n 名员工。他们现在就一些

alternative cake manufacturing(acm)有 n 名员工。他们现在就一些非常重要的问题

                                           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

  1. 5
  2. DDRRR

Output

D

Input

  1. 6
  2. 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分别按照顺序可以使对方出局和禁言,然后留下的最后一个就是胜者

思路:

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

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n;//表示D和R的数量
  4. char a[200005];//用来存储输进来的数据
  5. queue<int> d,r;//定义两个队列分别用来存放D和R的
  6. int main()
  7. {
  8. while(~scanf("%d",&n))//输入D和R总数量
  9. {
  10. scanf("%s",a);//输入整个字符
  11. for(int i=0;i<n;i++)
  12. {
  13. if(a[i]=='D') d.push(i);//分开两个队列
  14. else r.push(i);
  15. }
  16. while(!r.empty()&&!d.empty())//该题的核心代码
  17. {
  18. int R=r.front();//如果没有被吃掉的话,就将这个字母移到对列的末尾
  19. int D=d.front();
  20. if(R<D)
  21. {
  22. r.pop();
  23. d.pop();
  24. r.push(n+R);
  25. }
  26. else
  27. {
  28. d.pop();
  29. r.pop();
  30. d.push(n+D);
  31. }
  32. }
  33. if(!r.empty()) printf("R\n");//如果r队列有剩余的话,那么就说明R赢了
  34. else printf("D\n");
  35. }
  36. return 0;
  37. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/75781
推荐阅读
相关标签
  

闽ICP备14008679号