题意:$m$个士兵,每个士兵都有一个灵敏度$a[i]$,起点为$0$,终点为$n + 1$,在路上有$k$个陷阱,每个陷阱有三个属性$l[i],r[i],d[i]$,$l[i]$表示陷阱的位置,如果你走到$r[i]$这个位置,则可以拆掉这个陷阱,$d[i]$与士兵的灵敏度对应,如果$d[i]>a[j]$,则这个士兵就会被困住,现在你可以挑选任意数量的士兵,你有两种方式移动方式:

  • 带着士兵移动,但士兵不能被陷阱困住,每秒只能移动一格,从$x$到$x+1$或者$x-1$
  • 一个人去拆除陷阱$($你不会被陷阱困住$)$,每秒移动一格,从$x$到$x+1$或者$x-1$

问你最多可以带多少士兵,在时间$t$内移动到终点

思路:二分答案或者二分可以挑选士兵的最小灵敏度都可以,每次贪心带灵敏度最高的士兵,关键是二分后如何计算移动的最小时间,显然当多个陷阱的$l[i],r[i]$有交叉时,应该一个人继续前进拆除陷阱,直到$l[i],r[i]$没有交叉时回到士兵的位置带着士兵前进,否则直接回到士兵的位置,直到再次遇到能困住士兵的陷阱,一直这样到终点,$l[i],r[i]$相互交叉的部分则可以用差分、前缀和来处理,记录每个点的覆盖情况,计算被覆盖区间的总长度。

#include <iostream>
#include <algorithm>
#include <cstdio> using namespace std; const int N = ; struct node {
int l, r, d;
}; int a[N], cnt[N];
int n, m, k, t;
node p[N]; bool cmp(int a, int b)
{
return a > b;
} bool check(int mid)
{
int imin = a[mid], tt = ;
for (int i = ; i <= n + ; i++) cnt[i] = ;
for (int i = ; i <= k; i++)
if (p[i].d > imin)
cnt[p[i].l]++, cnt[p[i].r + ]--;
for (int i = ; i <= n + ; i++) cnt[i] += cnt[i - ];
for (int i = ; i <= n + ; i++)
if (cnt[i] >= ) tt++;
tt = * tt + n + ;
return tt > t;
} int main()
{
scanf("%d%d%d%d", &m, &n, &k, &t);
for (int i = ; i <= m; i++)
scanf("%d", &a[i]);
for (int i = ; i <= k; i++)
scanf("%d%d%d", &p[i].l, &p[i].r, &p[i].d);
sort(a + , a + m + , cmp);
int l = , r = m;
while (l < r) {
int mid = (l + r + ) >> ;
if (check(mid)) r = mid - ;
else l = mid;
}
printf("%d\n", l);
return ;
}

Educational Codeforces Round 77 (Rated for Div. 2) - D. A Game with Traps(二分)的更多相关文章

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

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

  2. 【cf比赛记录】Educational Codeforces Round 77 (Rated for Div. 2)

    比赛传送门 这场题目前三题看得挺舒服的,没有臃肿的题目,对于我这种英语渣渣就非常友好,但因为太急了,wa了两发A后才意识到用模拟(可以删了,博主真的是个菜鸟),结果导致心态大崩 ---- 而且也跟最近 ...

  3. Educational Codeforces Round 77 (Rated for Div. 2)

    A: 尽可能平均然后剩下的平摊 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int ...

  4. Codeforce |Educational Codeforces Round 77 (Rated for Div. 2) B. Obtain Two Zeroes

    B. Obtain Two Zeroes time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Educational Codeforces Round 77 (Rated for Div. 2)D(二分+贪心)

    这题二分下界是0,所以二分写法和以往略有不同,注意考虑所有区间,并且不要死循环... #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> ...

  6. Educational Codeforces Round 77 (Rated for Div. 2) C. Infinite Fence

    C. Infinite Fence 题目大意:给板子涂色,首先板子是顺序的,然后可以涂两种颜色,如果是r的倍数涂成红色,是b的倍数涂成蓝色, 连续的k个相同的颜色则不能完成任务,能完成任务则输出OBE ...

  7. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 【二分 + 尺取】

    任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second mem ...

  8. Educational Codeforces Round 88 (Rated for Div. 2) C. Mixing Water(数学/二分)

    题目链接:https://codeforces.com/contest/1359/problem/C 题意 热水温度为 $h$,冷水温度为 $c\ (c < h)$,依次轮流取等杯的热冷水,问二 ...

  9. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot(二分或者尺取)

    题目哦 题意:给出一个序列,序列有四个字母组成,U:y+1,D:y-1 , L:x-1 , R:x+1;   这是规则 . 给出(x,y) 问可不可以经过最小的变化这个序列可以由(0,0) 变到(x, ...

随机推荐

  1. 【转载】Windows环境下JNI的实现实例

    转自:http://blog.csdn.net/jjunjoe/article/details/6987183 一.关于JNI: JNI(Java Native Interface):Java本地调用 ...

  2. bootstrap环境

    <!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  3. PHP正则表达式常用例子

    "^[0-9]*[1-9][0-9]*$" //正整数"^((-\d+)|(0+))$" //非正整数(负整数 + 0)"^-[0-9]*[1-9][ ...

  4. VS2015 编译程序时提示 无法查找或打开 PDB 文件

    “mode.exe”(Win32): 已加载“C:\Windows\System32\api-ms-win-core-file-l2-1-0.dll”.无法查找或打开 PDB 文件.“mode.exe ...

  5. [lua]紫猫lua教程-命令宝典-L1-01-05. if判断结构

    L1[if]01. 简单的if判断结构 没什么说得 if得基本结构如下 xxx= ) then testlib.traceprint("1-100") ) then testlib ...

  6. HL7解析器

    最近做了关于医疗的项目,用了HL7协议,以下是解析的代码: HL7解析器: using System; using System.Text; using System.Xml; using Syste ...

  7. jmeter plugin manager安装插件

    https://jmeter-plugins.org/wiki/PluginsManager/ 以websocket 插件为例 先安装plugin manger 第二步:打开jmetre  optio ...

  8. 各种颜色空间之间的转换算法(XYZ → Standard-RGB ,Standard-RGB → XYZ)

    http://www.easyrgb.com/en/convert.php#Result http://www.easyrgb.com/en/math.php

  9. CSS - div居中在屏幕中(水平居中 + 垂直居中)

    方法一代码 <div> <h1>404 Not Found.</h1> </div> <style> div { text-align: c ...

  10. 从csv文件里取数据作为请求参数,和把返回数据放到一个csv文件

    本来想把登陆后的token放到数组里,下一个参数用,但是貌似不支持数组,暂时先这样用了,并不麻烦,还很方便. 1.添加线程组等必要的东东后,添加csv配置器 2.进行设置 说明:csv文件设置不能读取 ...