题目大意:

一共有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的更多相关文章

  1. CodeForces 1260D(二分+贪心+差分)

    题意 https://vjudge.net/problem/CodeForces-1260D 有m个士兵,t秒,你要带尽可能多的士兵从0去n+1,且他们不能被杀死.路上有一些陷阱,陷阱d[i]会杀死能 ...

  2. Educational Codeforces Round 77 (Rated for Div. 2) D A game with traps

    题意:x正轴上有着一个陷阱的位置,开关和灵敏度,如果一个士兵灵敏度输给陷阱,他是过不去这个陷阱的幸运的是,你可以先过去把开关给关了,没错你是不怕陷阱的接下来呢你有操作,你移动一个,耗费一秒而你的团队需 ...

  3. 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]$表示陷阱的位置,如果你 ...

  4. Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集

    E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...

  5. Codeforces B. Mouse Hunt(强连通分解缩点)

    题目描述: Mouse Hunt time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  6. 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. ...

  7. Codeforces Round #792 (Div. 1 + Div. 2) // C ~ E

    比赛链接:Dashboard - Codeforces Round #792 (Div. 1 + Div. 2) - Codeforces C. Column Swapping 题意: 给定一个n*m ...

  8. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  10. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

随机推荐

  1. [set]Codeforces 830B-Cards Sorting

    Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Spring Cloud 系列之 Netflix Zuul 服务网关

    什么是 Zuul Zuul 是从设备和网站到应用程序后端的所有请求的前门.作为边缘服务应用程序,Zuul 旨在实现动态路由,监视,弹性和安全性.Zuul 包含了对请求的路由和过滤两个最主要的功能. Z ...

  3. Building Applications with Force.com and VisualForce(Dev401)(十五):Data Management: Data management Overview

    Dev401-016:Data Management: Data management Overview Course Objectives1.List typical data management ...

  4. latex中文支持ubuntu

    latex安装: sudo apt install texlive-full 中文字体安装: sudo apt-get install latex-cjk-all      字体包中包含bsmi,bk ...

  5. ASP.NET Core Authentication and Authorization

    最近把一个Asp .net core 2.0的项目迁移到Asp .net core 3.1,项目启动的时候直接报错: InvalidOperationException: Endpoint CoreA ...

  6. iOS 重构AppDelegate

    一.Massive AppDelegate AppDelegate 是应用程序的根对象,它连接应用程序和系统,确保应用程序与系统以及其他应用程序正确的交互,通常被认为是每个 iOS 项目的核心. 随着 ...

  7. Premultiplied Alpha

    Xcode 的工程选项里有一项 Compress PNG Files,会对 PNG 进行 Premultiplied Alpha.游戏开发中会更加关注这个格式,省一些运行时计算. Premultipl ...

  8. SpringBoot使用RedisTemplate操作Redis时,key值出现 \xac\xed\x00\x05t\x00\tb

    原因分析 原因与RedisTemplate源码中的默认序列化方式有关 defaultSerializer = new JdkSerializationRedisSerializer( classLoa ...

  9. mavlink协议移植问题

    mavlink协议移植问题 mavlink源代码是一个代码库,使用的时候只需要将mavlink.h头文件包含到工程项目中即可. mavlink通信协议是无状态的连接,一般采用心跳消息跟踪系统是否存在. ...

  10. 模块 collections 高级数据类型

    collections模块 原文来自cnblog 的 Eva-J Eva-J 介绍了collections模块的常用方法,和演示实例 在 Python cookbook 的第一章中还有一些 更加好玩的 ...