CF/div2c/贪心
题目链接【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/贪心的更多相关文章
- CF - 高精度 + 贪心
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two foll ...
- *cf.4 贪心
D. Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input stand ...
- CF #374 (Div. 2) D. 贪心,优先队列或set
1.CF #374 (Div. 2) D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...
- CF 628C --- Bear and String Distance --- 简单贪心
CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...
- CF 949D Curfew——贪心(思路!!!)
题目:http://codeforces.com/contest/949/problem/D 有二分答案的思路. 如果二分了一个答案,首先可知越靠中间的应该大约越容易满足,因为方便把别的房间的人聚集过 ...
- 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 ...
- CF 435B Pasha Maximizes(贪心)
题目链接: [传送门][1] Pasha Maximizes time limit per test:1 second memory limit per test:256 megabytes ...
- CF 115B Lawnmower(贪心)
题目链接: 传送门 Lawnmower time limit per test:2 second memory limit per test:256 megabytes Description ...
- [CF #288-C] Anya and Ghosts (贪心)
题目链接:http://codeforces.com/contest/508/problem/C 题目大意:给你三个数,m,t,r,代表晚上有m个幽灵,我有无限支蜡烛,每支蜡烛能够亮t秒,房间需要r支 ...
随机推荐
- .Net 第三方工具包整理
抓取数据 Jumony (http://www.jumony.net/)是一个基于 .NET 技术,用 C# 编写的一个 HTML 引擎,其可以用来分析解读 HTML 文档中的数据,也可以修改和绑定数 ...
- 【实验室笔记】C#以本地时间创建txt文件
前段时间做的一个小项目,要求上位机在打开时候,以打开软件的系统时间的建立一个txt文件来存储下位机发送来的数据. 在第一版上位机上,取名的办法太弱了,先是读取系统时间,然后截取字符串,太笨拙.昨天,查 ...
- 获取控件id
普通状态中JS获取控件IDdocument.getElementById('controlID'); JS获取父窗口控件IDwindow.parent.document.getElementById( ...
- 一个挺好用的任务提示小软件 Rainlendar2
Rainlendar2 可以把任务列出来放到桌面上.
- iOS CGRectContainsPoint的用法
判断给定的点是否被一个CGRect包含,可以用CGRectContainsPoint函数 CGPoint point = [touch locationInView:self]; if(CGRectC ...
- [Rails] 从 Request 到 Response(2)
本文翻译自:Rails from Request to Response 系列:个人选择了自己感兴趣的部分进行翻译,需要阅读原文的同学请戳前面的链接. 第二部分 路由(Routing) Blog::A ...
- Delphi @ # $ 特殊字符含义
^: 指针 @: 取址 #: 十进制符 $: 十六进制符
- C#委托与事件讲解(一)
首先,我们还是先说说委托吧,从字面上理解,只要是中国人应该都知道这个意思,除非委托2个中文字不认识,举个例子,小明委托小张去买车票. 但是在我们的程序世界里,也是这么的简单吗?当然,什么是OO ...
- pthon之异常、文件练习题
1.在当前目录下查找文件夹“电摄班”,如果不存在则创建2.在电摄班下创建boys.girls.两个txt文件3.将字典中属于电摄班的同学按男女区分,分别放到boys.girls文件中,每个名字在文件中 ...
- js实现搜索框响应回车键
1.HTML页面, 注意:不要用使用form标签. Html代码 收藏代码<input type="text" name="keyword" id=&qu ...