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

题意:给出一个长度为n序列包含D和R,每一轮操作的先后顺序是1—n,规则是每一轮每个人有一次机会杀掉一个人,人死不能复生。问到最后剩下的人是D类人还是R类人。

思路:贪心+模拟。如果某个人有机会杀人,要杀掉还有机会杀人的不同类人,如果没有就杀掉位子靠前的已经用过杀人机会的不同类人。

#include<bits/stdc++.h>
using namespace std;
const int maxn=;
char s[maxn];
int n;
set<int>sr,sd;
int main ()
{
while(~scanf("%d",&n))
{
sr.clear(); sd.clear();
scanf("%s",s+);
for(int i = ;i <= n;i++)
{
if(s[i] == 'R')
sr.insert(i);
else
sd.insert(i);
}
while(sd.size()&&sr.size())
{
set<int>::iterator r = sr.begin();
set<int>::iterator d = sd.begin();
while(r != sr.end() && d != sd.end())
{
if(*r > *d)
{
set< int > :: iterator t= r;
r++; d++;
sr.erase(*t);
}
else
{
set<int>::iterator t=d;
d++; r++;
sd.erase(*t);
}
}
while(r!=sr.end())
{
if(sd.size())
{
sd.erase(*sd.begin());
r++;
}
else break;
}
while(d!=sd.end())
{
if(sr.size())
{
sr.erase(*sr.begin());
d++;
}
else break;
}
}
if(sr.size())
printf("R\n");
else
printf("D\n");
}
return ;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
queue<int>qud,qur;
char s[maxn];
int n;
int main ()
{
while(~scanf("%d",&n))
{
while(!qud.empty()) qud.pop();
while(!qur.empty()) qur.pop();
scanf("%s",s+);
for(int i=;i<=n;i++)
{
if(s[i]=='R')
qur.push(i);
else
qud.push(i);
}
while(!qur.empty()&&!qud.empty())
{
int r=qur.front();qur.pop();
int d=qud.front();qud.pop();
if(r>d)
qud.push(d+n);
else
qur.push(r+n);
}
if(qur.empty())
printf("D\n");
else
printf("R\n");
}
return ; }

CF/div2c/贪心的更多相关文章

  1. CF - 高精度 + 贪心

    Last year Bob earned by selling memory sticks. During each of n days of his work one of the two foll ...

  2. *cf.4 贪心

    D. Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input stand ...

  3. CF #374 (Div. 2) D. 贪心,优先队列或set

    1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...

  4. CF 628C --- Bear and String Distance --- 简单贪心

    CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...

  5. CF 949D Curfew——贪心(思路!!!)

    题目:http://codeforces.com/contest/949/problem/D 有二分答案的思路. 如果二分了一个答案,首先可知越靠中间的应该大约越容易满足,因为方便把别的房间的人聚集过 ...

  6. CF #296 (Div. 1) B. Clique Problem 贪心(构造)

    B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. CF 435B Pasha Maximizes(贪心)

    题目链接: [传送门][1] Pasha Maximizes time limit per test:1 second     memory limit per test:256 megabytes ...

  8. CF 115B Lawnmower(贪心)

    题目链接: 传送门 Lawnmower time limit per test:2 second     memory limit per test:256 megabytes Description ...

  9. [CF #288-C] Anya and Ghosts (贪心)

    题目链接:http://codeforces.com/contest/508/problem/C 题目大意:给你三个数,m,t,r,代表晚上有m个幽灵,我有无限支蜡烛,每支蜡烛能够亮t秒,房间需要r支 ...

随机推荐

  1. mac上设置sudo不要密码

    觉得每次sudo都需要设置密码太过麻烦,于是折腾了一番,谁知走了一番弯路记录下来. 以下是网上找到的步骤 chmod u+w /etc/sudoers  给当前用户增加写权限 vi /etc/sudo ...

  2. 推荐几个好的 Maven 常用仓库网址

    注意,以下内容转载自:推荐几个好的 Maven 常用仓库网址 Maven 确确实实是个好东西,用来管理项目显得很方便,但是如果是通过 Maven 来远程下载 JAR 包的话,我宿舍的带宽是4兆的,4个 ...

  3. HDU 5839 Special Tetrahedron

    HDU 5839 Special Tetrahedron 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n ...

  4. 去掉word冗余格式 java正则表达式

    word转换html时,会留下很多格式,有些格式并不是我们所需要的,然而这些格式比真正的文章内容还要多,严重影响页面的加载速度,因此就需要找个一个好的解决方案把这些多余的格式个去掉.网上有很多去除wo ...

  5. 手动搭建SSI框架

    SSI框架为struts.spring.ibatis,在该框架中,使用ibatis作为数据持久层,其中ibatis使用最新版本mybatis3. 注:本文使用版本:struts-2.3.4.sprin ...

  6. util:properties与context:property-placeholder

    spring 使用注解装配的Bean如何使用property-placeholder属性配置中的值 这个问题不大不小,以前偷懒凡是碰到需要引用属性文件中的类时就改用xml来配置. 今天看了下sprin ...

  7. 不使用jquery情况下循环添加绑定事件方法

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. push类型消息中间件-消息发布者(二)

    1.消息发布者声明 我们以spring的方式来声明一个消息发布者: <bean id="operateLogsMessageManager" class="com. ...

  9. Zend Studio 无法打开的解决办法

    今天郁闷的...正在写代码,突然 computer 嗝屁了,断电后自动重启了一次,开机后就悲剧了,Zend Studio 9 无法打开了,每次运行只弹窗个 请查看项目错误日志的提示 然后就没反应了.. ...

  10. L2-010. 排座位

    L2-010. 排座位 题目链接:https://www.patest.cn/contests/gplt/L2-010 并查集 相关题目:L2-007. 家庭房产,L3-003. 社交集群 下午打的时 ...