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 ...
随机推荐
- POJ1703 Find them Catch them 关于分集合操作的正确性证明 种类并查集
题目链接:http://poj.org/problem?id=1703 这道题和食物链那道题有异曲同工之处,都是要处理不同集合之间的关系,而并查集的功能是维护相同集合之间的关系.这道题中有两个不同的集 ...
- 两片74门实现的双边沿D触发器
最近一个项目需要时钟上升沿和下降沿都可以触发的D触发器,但并没有找到符合要求的商品IC.也去看了一些文献,但都是给的示意图然后用分立元件实现的(应该是准备做成IC).这里给出一种最少2个IC就能搭出来 ...
- C# 获取基类或者接口的所有继承类方法
static class ReflectionHelper { public static IEnumerable<T> CreateAllInstancesOf<T>() { ...
- Python python 五种数据类型--字典
# 定义一个字典 var1 = {'a':20,'b':40}; var2 = dict(); print(type(var1)) print(type(var2)) # 长度 length = le ...
- SQL 实战(五)
一. 将所有to_date为9999-01-01的全部更新为NULL,且 from_date更新为2001-01-01.CREATE TABLE IF NOT EXISTS titles_test ( ...
- MATLAB 动图绘制、保存
动图有gif格式和视频的avi格式. 1.sin(x)动图 clear all h = animatedline;%动画线 axis([0 4*pi -1 1]) box on x = linspac ...
- B. The Monster and the Squirrel
B. The Monster and the Squirrel Ari the monster always wakes up very early with the first ray of the ...
- stm32:实现呼吸灯
1.main.c #include "sys.h" #include "delay.h" #include "key.h" #define ...
- 《Three.js 入门指南》2.3.1- 照相机 - 正交投影demo
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- CentOS8中安装maven
下载maven,具体目录可根据实际情况而定 # wget http://mirrors.cnnic.cn/apache/maven/maven-3/3.3.9/binaries/apache-mave ...