D - A Game with Traps-- codeforces 1260D A
题目大意:
一共有m个士兵,k个陷阱,时间为t,一个首领,这个首领需要在t时间内尽可能多的将士兵带到boos的面前, 第二行是每个士兵的灵敏度。
紧接着是k个陷阱,每个陷阱有l,,r,,d组成,l代表陷阱的位置,r代表l处的陷阱可以在位置r处被解决,陷阱的灵敏度是d,当陷阱的灵敏度比士兵的灵敏度大时,则可以杀掉士兵。陷阱对首领没有用。
问首领最多可以将多少名士兵带到boos的面前。
题解:二分+贪心。
首先根据这些士兵的灵敏度,从高到低进行排序,然后二分取第x灵敏度的士兵记为mi,然后将陷阱灵敏度大于mi的陷阱挑出来。接下来就是暴力模拟。将这些陷阱按照 l 升序排列。然后我们记录一下当前的士兵的位置。
如果说陷阱消除位置比士兵当前位置小,那么说明此陷阱已经被消除了,不用考虑。否则,我们需要首领带着士兵走到当前陷阱的位置l-1处,然后首领在去消除陷阱。陷阱消除位置一定在l的右侧,也就说
小于r的所以陷阱都已经被消除了。直接让arrive=l-1;
最后在ans=ans*2+n+1;
因为首领消除陷阱需要往返。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2E5+;
const ll INF=1e9+;
ll n,m,k,t;
ll arr[N];
bool cmp(const ll &x,const ll &y) {
return x>y;
}
struct stu{
ll l,r,d;
}trap[N];
stu c[N];
bool cmp2(const stu &x,const stu &y){
return x.l<y.l;
}
bool check(ll x){
ll mi=arr[x];
ll pos=;
for(ll i=;i<=k;i++){
if(trap[i].d>mi) {
c[pos++]=trap[i];
}
}
ll arrive=;
ll time=;
sort(c,c+pos,cmp2);
for(ll i=;i<pos;i++){
if(c[i].r<=arrive)
continue;
arrive=max(arrive,c[i].l-);
time+=c[i].r-arrive;
arrive=c[i].r;
}
time=n++time*;
return time<=t;
}
int main(){
ios::sync_with_stdio();
cin>>m>>n>>k>>t;
for(ll i=;i<=m;i++) cin>>arr[i];
sort(arr+,arr++m,cmp);
for(ll i=;i<=k;i++) cin>>trap[i].l>>trap[i].r>>trap[i].d;
ll left=;
arr[]=INF;
ll right=m,ans=;
while(right>=left){
ll mid=(left+right)/;
if(check(mid)){
ans=max(ans,mid);
left=mid+;
}
else right=mid-;
}
cout<<ans<<endl;
return ;
}
D - A Game with Traps-- codeforces 1260D A的更多相关文章
- CodeForces 1260D(二分+贪心+差分)
题意 https://vjudge.net/problem/CodeForces-1260D 有m个士兵,t秒,你要带尽可能多的士兵从0去n+1,且他们不能被杀死.路上有一些陷阱,陷阱d[i]会杀死能 ...
- Educational Codeforces Round 77 (Rated for Div. 2) D A game with traps
题意:x正轴上有着一个陷阱的位置,开关和灵敏度,如果一个士兵灵敏度输给陷阱,他是过不去这个陷阱的幸运的是,你可以先过去把开关给关了,没错你是不怕陷阱的接下来呢你有操作,你移动一个,耗费一秒而你的团队需 ...
- Educational Codeforces Round 77 (Rated for Div. 2) - D. A Game with Traps(二分)
题意:$m$个士兵,每个士兵都有一个灵敏度$a[i]$,起点为$0$,终点为$n + 1$,在路上有$k$个陷阱,每个陷阱有三个属性$l[i],r[i],d[i]$,$l[i]$表示陷阱的位置,如果你 ...
- Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集
E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...
- Codeforces B. Mouse Hunt(强连通分解缩点)
题目描述: Mouse Hunt time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Educational Codeforces Round 74 (Rated for Div. 2) B. Kill 'Em All
链接: https://codeforces.com/contest/1238/problem/B 题意: Ivan plays an old action game called Heretic. ...
- Codeforces Round #792 (Div. 1 + Div. 2) // C ~ E
比赛链接:Dashboard - Codeforces Round #792 (Div. 1 + Div. 2) - Codeforces C. Column Swapping 题意: 给定一个n*m ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
随机推荐
- 数据库-Mysql语句
Mysql语句 不定时更新 1.数据库相关的语句 /* 数据库操作 */ ------------------ -- 启动MySQL net start mysql -- 接与断开服务器 mysql ...
- 动态网站项目(Dynamic Web Project)登录功能的实现(mvc(五层架构)+jdbc+servlet+tomcat7.0+jdk1.8)(js验证+cookie)
1.index.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" p ...
- 用python的BeautifulSoup分析html
序言 之前用python爬取网页的时候,一直用的是regex或者自带的库sgmllib里的SGMLParser.但是遇到复杂一点的情况时,SGMLParser往往就不那么给力了!(哈,难道说我 too ...
- Kaggle大牛小姐姐自述:我是怎么成为竞赛中Top 0.3%的 | 干货攻略
天天跟数据打交道的研究人员,都有一个成为Kaggle顶级大师(Grandmaster)的梦想. 但每年的Kaggle参赛团队众多,通常一个项目都有数千人至上万人报名,如何在其中脱颖而出? 最近,自动化 ...
- python框架-Django创建项目
创建项目 django-admin startproject douban//创建project cd douban python manage.py startapp books//创建app项目 ...
- redis++:Redis的两种持久化 RDB 和 AOF
Redis持久化备份数据的方式有两种:RDB(Redis DataBase) . AOF(Append Only File). RDB 什么是RDB: 在指定时间间隔内,将内存中的数据集快照写入磁盘 ...
- CocoaPods 安装卸载
建议升级10.15的系统,什么都装好了 sudo gem install cocoapods pod setup搞定不能有search命令,可以pod init,下载用的是cdn,打开项目正常使用 问 ...
- sql MYSQL主从配置
MYSQL主从配置 1.1 部署环境 主(master_mysql): 192.168.1.200 OS:CentOS 6.5 从(slave_mysql): 192.168.1.201 OS:Cen ...
- NKOJ3772 看电影
问题描述 共有m部电影,编号为1~m,第i部电影的好看值为w[i]. 在n天之中(从1~n编号)每天会放映一部电影,第i天放映的是第f[i]部. 你可以选择l,r(1<=l<=r<= ...
- for、forEach、for-in与for-of的区别
let arr=[1,2,3,4,5]; arr.b='100'; for for(let i=0;i<arr.length;i++){ console.log(arr[i]); } for是编 ...