题目链接: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. 硬盘安装linux的两条命令

    kernel (hd0,0)/vmlinuz boot=casper iso-scan/filename=/ubuntu-10.04.1-desktop-i386.iso ro quiet splas ...

  3. Tiny Mapper

    今天看到一个对象映射工具-TinyMapper 1.介绍 Tiny Mapper是一个.net平台的开源的对象映射组件,其它的对象映射组件比如AutoMapper有兴趣的可以去看,Tiny Mappe ...

  4. mysql 优化

    1.存储过程造数据 CREATE DEFINER=`root`@`localhost` PROCEDURE `generate_test_data`(`n` int) begin declare i ...

  5. JS学习:第二周——NO.2正则

    1.[正则] 就是用来操作(匹配和捕获)的一系列规则: 匹配:校验字符串是否符合我们的规则:返回值--布尔值           匹配这里用的是正则的方法:test(),reg.text( ); 捕获 ...

  6. 阿里无线前端性能优化指南 (Pt.1 加载优化)

    前言 阿里无线前端团队在过去一年对所负责业务进行了全面的性能优化.以下是我们根据实际经验总结的优化指南,希望对大家有所帮助. 第一部分仅包括数据加载期优化. 图片控制 对于网页特别是电商类页面来说,图 ...

  7. shell脚本: 备份mysql远程数据库并清除一个月之前的数据

    hxingxing-backup.sh: date="$(date +"%Y-%m-%d")"mysqldump -u root -h localhost -p ...

  8. CSS中不定宽块状元素的水平居中显示

    CSS中不定宽块状元素的水平居中显示 慕课网上的HTML/CSS教程 http://www.imooc.com/view/9 其中有三种方法 第一种是加入table标签 任务是实现div元素的水平居中 ...

  9. linux Mint 安装apache2

    sudo apt-get install apache2 y 启动apache2  /etc/init.d/apache2 restart 浏览器输入localhost看看是否访问正常 apache2 ...

  10. 关于清除arp 缓存的那点事儿

    在Linux下,清除arp缓存表,例如: arp -d 10.0.3.6 我们可以用上面这条命令清除某一条记录,也可以用 arp -n |awk '/^[1-9]/{print "arp - ...