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 ...
随机推荐
- JSP(二)----指令,注释,内置对象
## JSP 1.指令 * 作用:用于配置JSP页面,导入资源文件 * 格式: <%@ 指令名称 属性名1=属性值1 属性名2=属性值2 %> <%@ page con ...
- 「SWTR-04」Sweet Round 04 游记
比赛链接 由于 \(\texttt{Sweet Round}\) 比赛挺好的(关键不知道为啥\(Unrated\) 开篇总结(大雾):这次比赛题目不错(有思维含量) 尽管我不会做. 我一看 \(T1\ ...
- python学习(五)之列表元素的积
前几天,学完python的列表之后,我们老师留了一道关于列表的题目.几天后,老师讲解习题,很荣幸成为被老师点名讲解自己代码的其中之一下面把我的想法分享一下. 描述一个由n(n>1)个数字组成的列 ...
- In Triangle Test / To Left Test
2020-01-09 14:51:29 如何高效的判断一个点是否是包含在一个三角形的内部是计算几何里的一个基础问题. In Triangle Test问题也可以用来解决计算几何里的一个基础问题就是 凸 ...
- Diagnostics: File file:/private/tmp/spark-d4ebd819-e623-47c3-b008-2a4df8019758/__spark_libs__6824092999244734377.zip does not exist java.io.FileNotFoundException: File file:/private/tmp/spark-d4ebd819
spark伪分布式模式 on-yarn出现一下错误 Diagnostics: File file:/private/tmp/spark-d4ebd819-e623-47c3-b008-2a4df801 ...
- pycharm创建虚拟环境venv和添加依赖库package
1.创建虚拟环境 因为项目采用不同版本的python,所依赖的库的版本也不一样,为了避免版本冲突,为每一个项目每个python版本创建一个虚拟环境,环境中所使用的依赖库也是独立存在,不会被其他版本或其 ...
- Github标星3K+,热榜第三,一网打尽数据科学速查表
这几天,Github上的趋势榜一天一换. 这次一个名为 Data-Science--Cheat-Sheet 的项目突然蹿到了第三名. 仔细一看,确实干货满满.来,让文摘菌推荐一下~ 这个项目本质上是备 ...
- Html,css构建一个对话框,练习201911281028
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- Django-利用Form组件和ajax实现的注册
利用Form组件和ajax实现的注册 一.注册相关的知识点 1.Form组件 我们一般写Form的时候都是把它写在views视图里面,那么他和我们的视图函数也不影响,我们可以吧它单另拿出来,在应用下面 ...
- D - Expanding Rods POJ - 1905(二分)
D - Expanding Rods POJ - 1905 When a thin rod of length L is heated n degrees, it expands to a new l ...