因为题目中要求使连续死亡的机器人最多,令人联想到二分答案。

考虑如何检验这之中是否存在一段连续的长度为md的区间,其中花最多k步使得它们都死亡。

这个条件等价于区间中m个最大值的和不超过k。

枚举起点,可以用 $ O(mlogn) $ 的时间确定这段区间是否合法,最终check的复杂度是 $ O(nmlogn) $。

总复杂度是 $ O(nmlog^{2}n) $。

$ \bigodot $ 技巧&套路:

  • 最大(小)值的问题,可以考虑二分答案。
  • check时用线段树优化区间平移,来枚举每一个长度固定的区间。
 #include <cstdio>
#include <iostream>
#include <algorithm> const int N = ; int n, m, k, re;
int a[N][], ans[], tmp[]; namespace SE {
int ma[][N << ];
inline void Up(int t) {
for (int i = ; i <= m; ++i) {
ma[i][t] = std::max(ma[i][t << ], ma[i][t << | ]);
}
}
void Build(int t, int l, int r) {
if (l == r) {
for (int i = ; i <= m; ++i) ma[i][t] = a[l][i];
return;
}
int md = (l + r) >> ;
Build(t << , l, md);
Build(t << | , md + , r);
Up(t);
}
int Query(int t, int l, int r, int L, int R, int ty) {
if (L <= l && r <= R) return ma[ty][t];
int md = (l + r) >> , re = ;
if (L <= md) re = std::max(re, Query(t << , l, md, L, R, ty));
if (md < R) re = std::max(re, Query(t << | , md + , r, L, R, ty));
return re;
}
} inline int Check(int md) {
for (int i = ; i + md - <= n; ++i) {
int sum = ;
for (int j = ; j <= m; ++j) {
tmp[j] = SE::Query(, , n, i, i + md - , j);
sum += tmp[j];
if (sum > k) break;
}
if (sum <= k) {
for (int j = ; j <= m; ++j) ans[j] = tmp[j];
return ;
}
}
return ;
} int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = ; i <= n; ++i) {
for (int j = ; j <= m; ++j) {
scanf("%d", &a[i][j]);
}
}
SE::Build(, , n);
for (int nl = , nr = n, md; nl <= nr; ) {
md = (nl + nr) >> ;
if (Check(md)) {
re = md; nl = md + ;
} else {
nr = md - ;
}
}
if (re) Check(re);
for (int i = ; i <= m; ++i) {
printf("%d ", (re)? ans[i] : );
} return ;
}

【Cf #291 B】R2D2 and Droid Army(二分,线段树)的更多相关文章

  1. (困难) CF 484E Sign on Fence,整体二分+线段树

    Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence o ...

  2. Codeforces 514 D R2D2 and Droid Army(Trie树)

    题目链接 大意是判断所给字符串组中是否存在与查询串仅一字符之差的字符串. 关于字符串查询的题,可以用字典树(Trie树)来解,第一次接触,做个小记.在查询时按题目要求进行查询. 代码: #define ...

  3. Codeforces Round #291 (Div. 2) D. R2D2 and Droid Army [线段树+线性扫一遍]

    传送门 D. R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  4. R2D2 and Droid Army(多棵线段树)

    R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. HDU4614 Vases and Flowers 二分+线段树

    分析:感觉一看就是二分+线段树,没啥好想的,唯一注意,当开始摆花时,注意和最多能放的比大小 #include<iostream> #include<cmath> #includ ...

  6. J - Joseph and Tests Gym - 102020J (二分+线段树)

    题目链接:https://cn.vjudge.net/contest/283920#problem/J 题目大意:首先给你n个门的高度,然后q次询问,每一次询问包括两种操作,第一种操作是将当前的门的高 ...

  7. Educational Codeforces Round 61 D 二分 + 线段树

    https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...

  8. 【BZOJ-3110】K大数查询 整体二分 + 线段树

    3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 6265  Solved: 2060[Submit][Sta ...

  9. hdu6070 Dirt Ratio 二分+线段树

    /** 题目:hdu6070 Dirt Ratio 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6070 题意:给定n个数,求1.0*x/y最小是多少.x ...

  10. K-th occurrence HDU - 6704 (后缀数组+二分线段树+主席树)

    大意: 给定串s, q个询问(l,r,k), 求子串s[l,r]的第kk次出现位置. 这是一篇很好的题解: https://blog.csdn.net/sdauguanweihong/article/ ...

随机推荐

  1. Ubuntu 16.04安装tensorflow_gpu的方法

    参考资料: Ubuntu 16.04安装tensorflow_gpu 1.9.0的方法 装Tensorflow,运行项目报错: module compiled against API version ...

  2. 从零系列--node爬虫利用进程池写数据

    1.主进程 const http = require('http'); const fs = require('fs'); const cheerio = require('cheerio'); co ...

  3. Oz 创建Ubuntu镜像

    参考链接: http://blog.csdn.net/gcogle/article/details/52767135http://tlinux.blog.51cto.com/7288656/17497 ...

  4. eclipse以MapReduce本地模式运行程序

    1.准备好所需的文件winutils.exe.hadoop-eclipse-plugin-2.7.3.jar.hadoop-common-2.2.0-bin-master.zip 下载路径:http: ...

  5. Codeforces Round #515 (Div. 3) 解题报告(A~E)

    题目链接:http://codeforces.com/contest/1066 1066 A. Vova and Train 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在 ...

  6. linux安装nginx并配置负载均衡

    linux上安装nginx比较简单: 前提是需要有gcc或者g++ 1.yum需要的依赖  yum -y install openssl openssl-devel 2.解压pcre库.zlib库   ...

  7. centos下部署禅道流程

    原文摘录:https://www.jianshu.com/p/71e9dab130a5 下面将我在Linux系统下搭建禅道服务的过程分享给大家. 第一步:下载禅道 Linux中可以用以下命令来下载安装 ...

  8. C++:模板——函数模板1

    一.为什么使用函数模板 假设我们在程序中需要比较两个变量的大小,但变量的类型可能是int.float或者double,此时为了满足程序的要求我们可能会在程序中编写多个函数,如: //比较两个int型变 ...

  9. “Gogoing”改进方案

    通过看见他们对我们团队的意见点评,我们还要有更多改善的地方. 首先,就是界面的优化: 其次,加上自己些特有的功能,吸引更多的用户: 然后,需要整理大量的数据库信息才能完善: 最后,需要有其他软件的集成 ...

  10. Task 6.4 冲刺Two之站立会议7

    今天又重新对服务器部分加以分析改进,由于用户登录时必须得连接服务器,所以作为整个软件最核心的服务器的部分,只有保障了这个内容才能保证软件的正常运行.