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支 ...
随机推荐
- Zeppelin使用Spark的yarn-client模式
Zeppelin版本0.6.2 1. Export SPARK_HOME In conf/zeppelin-env.sh, export SPARK_HOME environment variable ...
- OOP的方法
<?php class Computer{ //我要创建一个构造方法 public function __construct(){ echo '我是比较先进的构造方法!'; //构造方法一般用于 ...
- Linux kernel Vhost-net 和 Virtio-net代码详解
场景 Host上运行qemu kvm虚拟机,其中虚拟机的网卡类型为virtio-net,而Host上virtio-net backend使用vhost-net 数据包进入虚拟机代码分析 首先看vhos ...
- Python----文件的IO操作
一.文件操作 r 以只读方式打开文件.文件的指针将会放在文件的开头.这是默认模式. rb 以二进制格式打开一个文件用于只读.文件指针将会放在文件的开头.这是默认模式. r+ 打开一个文件用于读写.文件 ...
- HDU 1847 Good Luck in CET-4 Everybody! 博弈
题目思路: 写出SG函数(1表示先手胜,0表示先手负) 110110110110-- 发现n%3==0时,Cici胜 #include<stdio.h> #include<strin ...
- C# 常用接口学习 ICollection<T>
C# 常用接口学习 ICollection<T> 作者:乌龙哈里 时间:2015-11-01 平台:Window7 64bit,Visual Studio Community 2015 参 ...
- hibernate 和 jdbc 优缺点对比
jdbc缺点: 1.编程繁琐,用的try和catch比较多 2.jdbc没有对数据做缓存 3.没有做到面向对象编程 4.sql语句的跨平台性很差 jdbc优点: 效率比较高 hibernate的优点: ...
- oracle 删除当前用户下所有的表、索引、序列...
select 'drop table "' || table_name ||'";'||chr(13)||chr(10) from user_tables; --delete t ...
- fido-uaf-protocol-v1.0
EXAMPLE 1: Policy matching either a FPS-, or Face Recognition-based Authenticator { "accepted&q ...
- System.Diagnostics.Process 执行.EXE
分类: C#+WINFORM 2009-04-05 21:09 459人阅读 评论(0) 收藏 举报 我们经常会遇到在Winform或是WPF中点击链接或按钮打开某个指定的网址, 或者是需要打 ...