题目链接:http://codeforces.com/contest/749/problem/C

题意:给定一个长度为n的D/R序列,代表每个人的派别,然后进行发表意见,顺序是从1到n。每个人到他的回合可以踢掉一个人。被踢掉的人不能参与发表直接跳过他的回合。如此知道剩下一个人。输出那个人所在的派别。

思路:明显的贪心题。为了让同派别的尽可能的留下来,所以应当踢掉在他后面的并且离他最近的其他派别的人。这样后面同派别的人才能发表。如果后面不存在其他派别的人,则应该踢掉前面离他最远的其他派别的人(应该离他最远的下一轮会是先手)。 然后就是按照思路模拟了。

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<time.h>
#include<cmath>
using namespace std;
typedef long long int LL;
const int MAXN = + ;
char str[MAXN];
int main(){
//#ifdef kirito
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
//#endif
// int start = clock();
int n;
while (scanf("%d", &n) != EOF){
scanf("%d", &n); scanf("%s", str);
set<int> D, R; int totD = , totR = ;
for (int i = ; i < n; i++){
if (str[i] == 'D'){ D.insert(i); totD++; }
else{ R.insert(i); totR++; }
}
while (totR&&totD){
set<int>::iterator it;
for (int i = ; i < n&&totR&&totD; i++){
if (str[i] == '#'){ continue; } //已经被vote
if (str[i] == 'D'){
it = R.upper_bound(i); //找到后面理他最近的人
if (it == R.end()){ //后面没有,则找前面第一个还在的
it = R.begin();
}
str[*it] = '#'; R.erase(it);
totR--;
}
else{
it = D.upper_bound(i);
if (it == D.end()){
it = D.begin();
}
str[*it] = '#'; D.erase(it);
totD--;
}
}
}
printf("%c\n", totD ? 'D' : 'R');
}
//#ifdef LOCAL_TIME
// cout << "[Finished in " << clock() - start << " ms]" << endl;
//#endif
return ;
}

Codeforces Round #388 (Div. 2) - C的更多相关文章

  1. Codeforces Round #388 (Div. 2)

      # Name     A Bachgold Problem standard input/output 1 s, 256 MB    x6036 B Parallelogram is Back s ...

  2. Codeforces Round #388 (Div. 2) - B

    题目链接:http://codeforces.com/contest/749/problem/B 题意:给定平行四边形的3个点,输出所有可能的第四个点. 思路:枚举任意两个点形成的直线,然后利用这两个 ...

  3. Codeforces Round #388 (Div. 2) - A

    题目链接:http://codeforces.com/contest/749/problem/A 题意:给定一个数n,求把n分解成尽量多的素数相加.输入素数个数和具体方案. 思路:因为要尽量多的素数, ...

  4. Codeforces Round #388 (Div. 2) A,B,C,D

    A. Bachgold Problem time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #388 (Div. 2) 749E(巧妙的概率dp思想)

    题目大意 给定一个1到n的排列,然后随机选取一个区间,让这个区间内的数随机改变顺序,问这样的一次操作后,该排列的逆序数的期望是多少 首先,一个随机的长度为len的排列的逆序数是(len)*(len-1 ...

  6. Codeforces Round #388 (Div. 2) D

    There are n people taking part in auction today. The rules of auction are classical. There were n bi ...

  7. Codeforces Round #388 (Div. 2) A+B+C!

    A. Bachgold Problem 任何一个数都可以由1和2组成,由于n是大于等于2的,也就是可以由2和3组成.要求最多的素数即素数越小越好,很明显2越多越好,如果n为奇数则再输出一个3即可. i ...

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

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

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. shell 计算

    1.整数计算 n=$((/)) echo $n 输出 2(注意必须是两个括号) exper / / 注意这里不支持括号,a%b,a/b后取余 output: 1 2.小数计算 bc <<& ...

  2. webservice客户端添加soap Header信息

    根据wsdl文件的header信息,在客户端中添加相应的header 1.wsdl信息如图 <soapenv:Envelope xmlns:soapenv="http://schema ...

  3. 关于Window Server2008 服务器上无法播放音频文件的解决方案

    在偌大的百度当中查找我所需要的资源信息,但网络上所描述的都不能解决,发生此类问题的人很多,但是都没有得到准确的解决方法!经个人各方面的尝试,其实非常简单的解决了无法播放音频文件的问题,如果各位今后也遇 ...

  4. JSP的9大内置对象

    1.概述 JSP的这9个内置对象,都是servlet API实例,即在JSP页面内部,可以直接使用; ps:顺便说下JSP的4大范围: JSP的四种范围,分别为page.request.session ...

  5. windows XP上实现python2.7.5和python3.4.3共存

    windows XP上实现python2.7.5和python3.4.3共存过程记录: 1. 首先安装python2.7.5和python3.4.3,两个版本安装顺序不分前后; 2. 检查系统环境变量 ...

  6. 【Android】Android属性allowBackup安全风险

    allowBackup值为true或false,Android API Level 8及其以上Android系统提供了为应用程序数据的备份和恢复功能,当allowBackup标志为true时,用户即可 ...

  7. Ajax商品分类三级联动实现

    思路分析: 效果:当页面加载时,利用ajax异步向后台请求数据,加载一级商品类别,当选择一级商品时加载二级商品,选择二级商品加载三级商品. 实现: 1.当拿到数据后加载pid为0的商品,并动态创建op ...

  8. Spring框架学习(二)

    一.Spring IOC参数值注入 1.注入基本值 1.1)<value></value>元素可以通过字符串指定属性或构造参数的值.容器将字符串从java.lang.Strin ...

  9. Django~待解决的问题

    1.一个Model.py中简单调用多个数据库,不写数据库路由

  10. Python: with...as...

    with open(path, 'r') as f: Soup = BeautifulSoup(f.read(), 'lxml') titles = Soup.select('ul > li & ...