zoukankan      html  css  js  c++  java
  • CodeForces

    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位序的大小
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<string.h>
     7 #include<set>
     8 #include<vector>
     9 #include<queue>
    10 #include<stack>
    11 #include<map>
    12 #include<cmath>
    13 typedef long long ll;
    14 typedef unsigned long long LL;
    15 using namespace std;
    16 const double PI=acos(-1.0);
    17 const double eps=0.0000000001;
    18 const ll mod=998244353;
    19 const int N=2000000+100;
    20 char str[N];
    21 int sum1[N];
    22 int sum2[N];
    23 int n;
    24 queue<int>R,D;
    25 int main(){
    26     while(scanf("%d",&n)!=EOF){
    27         scanf("%s",str+1);
    28         while(!D.empty())D.pop();
    29         while(!R.empty())R.pop();
    30         for(int i=1;i<=n;i++){
    31             if(str[i]=='D')D.push(i);
    32             else{
    33                 R.push(i);
    34             }
    35         }
    36         while(D.empty()==0&&R.empty()==0){
    37             int x=D.front();
    38             int y=R.front();
    39             if(x<y){
    40                 R.pop();
    41                 D.pop();
    42                 D.push(x+n);
    43             }
    44             else{
    45                 D.pop();
    46                 R.pop();
    47                 R.push(y+n);
    48             }
    49         }
    50         if(D.empty()==0){
    51             cout<<"D"<<endl;
    52         }
    53         else{
    54             cout<<"R"<<endl;
    55         }
    56     }
    57 }
    
    
  • 相关阅读:
    vue—子调父 $emit (把子组件的数据传给父组件)
    解决 Error: EBUSY: resource busy or locked, rmdir 'E:/...'问题
    php中session原理及安全性问题
    MySQL函数大全及用法示例
    php基础语法
    常用sql语句
    php表单传值--GET和POST
    jQuery插件的使用方法
    $.ajax()方法详解
    php文件上传
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/7309365.html
Copyright © 2011-2022 走看看