题目链接【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. sharepoint代码添加WebPart

    Adding a web part   Following code snippet can be used to add a web part in an existing SharePoint w ...

  2. Java开发工具

    总的来看Java的开发工具无非由两个部分构成,一个JDK一个是IDE,无论JDK是不可变的,IDE则是哪个用着舒服就用哪个. 1JDK 1.1简介 JDK是 Java 语言的软件开发工具包(SDK), ...

  3. Linux c 内存高速访问

    概述 要想高速利用内存就必须高效利用cpu cache,关于cpu cache这里就不多加讨论了,自己感兴趣可以google 而cpu访问内存的单位是cache line,因此高效利用cache li ...

  4. React Route

    有幸你能看来我的这篇文章,这篇文章是继React后面写的Reactroute,所以你需要看看我前面整理的React笔记再来看Reactroute可能更容易 All the work we've don ...

  5. SpringMVC初步——HelloWorld的实现

    开通博客园好几个月了,今天开始要用博客园记录自己的学习过程! 目录: 导包: 1. 配置web.xml文件的springDispatcherServlet 在xml中 alt+/ 找到springdi ...

  6. Android5.1源码Xposed框架编译

    介绍 Xposed框架是一款可以在不修改APK的情况下影响程序运行(修改系统)的框架服务,基于它可以制作出许多功能强大的模块,且在功能不冲突的情况下同时运作 . 对于Android5.1系统,官方提供 ...

  7. pull类型消息中间件-消息消费者(二)

    消费者的实例化 关于consumer的默认实现,metaq有两种: DefaultMQPullConsumer:由业务方主动拉取消息 DefaultMQPushConsumer:通过业务方注册回调方法 ...

  8. UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 26269: illegal multibyte sequence

    解决方法参见下面的链接: http://blog.csdn.net/jim7424994/article/details/22675759

  9. Python读取ini配置文件

    db_config.ini [baseconf] host=127.0.0.1 port=3306 user=root password=root db_name=evaluting_sys [con ...

  10. python 强制结束线程的坑

    网上流传了两种能强制结束线程的错误姿势 第一种:通过setDaemon来结束线程 http://www.cnblogs.com/jefferybest/archive/2011/10/09/22040 ...