Enduring Exodus CodeForces - 655C (二分)
大意: n个房间, 1为占用, 0为未占用, John要将k头奶牛和自己分进k+1个空房间, 求John距最远的奶牛距离的最小值
这种简单题卡了20min....
显然对于固定的k+1个房间, 只需要John在最接近中央的房间即可, 枚举每k个房间, 找出最接近的就行了
这样复杂度是$O(nlogk)$
还可以直接二分答案, 复杂度$O(nlogn)$
#include <iostream>
#include <algorithm>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
using namespace std; const int N = 4e5+10;
int n, k;
int a[N];
char s[N]; int main() {
scanf("%d%d%s", &n, &k, s+1);
REP(i,1,n) if (s[i]=='0') a[++*a] = i;
n = *a;
int ans = 1e9;
REP(i,1,n-k) {
int j = i+k;
int p = lower_bound(a+i,a+j+1,(a[i]+a[j])/2)-a-1;
REP(r,p,p+3) if (i<=r&&r<=j) {
ans = min(ans, max(abs(a[i]-a[r]),abs(a[j]-a[r])));
}
}
printf("%d\n", ans);
}
Enduring Exodus CodeForces - 655C (二分)的更多相关文章
- codeforces 655C C. Enduring Exodus(二分)
题目链接: C. Enduring Exodus time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- CROC 2016 - Elimination Round (Rated Unofficial Edition) C. Enduring Exodus 二分
C. Enduring Exodus 题目连接: http://www.codeforces.com/contest/655/problem/C Description In an attempt t ...
- Code Forces 645C Enduring Exodus
C. Enduring Exodus time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...
- Codeforces 645C Enduring Exodus【二分】
题目链接: http://codeforces.com/contest/645/problem/C 题意: 给定01串,将k头牛和农夫放进, 0表示可以放进,1表示不可放进,求农夫距离其牛的最大距离的 ...
- CodeForces - 645 C.Enduring Exodus
快乐二分 用前缀和随便搞一下 #include <cstdio> using namespace std; ; int p[N]; ; inline int msum(int a, int ...
- codeforces 645C . Enduring Exodus 三分
题目链接 我们将所有为0的位置的下标存起来. 然后我们枚举左端点i, 那么i+k就是右端点. 然后我们三分John的位置, 找到下标为i时的最小值. 复杂度 $ O(nlogn) $ #include ...
- CodeForces 645C Enduring Exodus
枚举,三分. 首先,这$n+1$个人一定是连续的放在一起的.可以枚举每一个起点$L$,然后就是在$[L,R]$中找到一个位置$p$,使得$p4最优,因为越往两边靠,距离就越大,在中间某位置取到最优解, ...
- CodeForces - 363D --二分和贪心
题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a ...
- Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论
n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...
随机推荐
- 9大行为导致Java程序员薪资过低, 你有几个?
Java程序员薪水有高有低,有的人一个月可能拿30K.50K,有的人可能只有2K.3K.同样有五年工作经验的Java程序员,可能一个人每月拿20K,一个拿5K.是什么因素导致了这种差异?本文整理导致J ...
- 【翻译】std::remove - C++ Reference
函数模板 std::remove 头文件<algorithm> template <class ForwardIterator, class T> ForwardIterato ...
- Wireshark 显示域名列
一般使用Wireshark只能看到ip地址,但是看域名更方便更简明 只要修改一个配置就可以 编辑-->首选项 勾选Resolve network(IP) addresses 重新捕捉:
- 解决Eclipse 项目报错:Unbound classpath container: ‘JRE System Library [JavaSE-1.7]
MyEclipse出现下面两条报错: The project cannot be built until build path errors are resolved HelloWord Unknow ...
- flink架构介绍
前言 flink作为基于流的大数据计算引擎,可以说在大数据领域的红人,下面对flink-1.7的架构进行逻辑上的分析并和spark做了一些关键点的对比. 架构 如图1,flink架构分为3个部分,cl ...
- 【Cuda编程】加法归约
目录 cuda编程并行归约 AtomicAdd调用出错 gpu cpu下时间计算 加法的归约 矩阵乘法 矩阵转置 统计数目 平方和求和 分块处理 线程相邻 多block计算 cuda编程并行归约 At ...
- Python Sip [RuntimeError: the sip module implements API v11.0 to v11.2 but the PyQt5.QtCore module requires API v11.3]
不知道原因,尝试卸载.编译安装均失败.只有这样曲线救国 import matplotlib matplotlib.use("WXAgg",warn=True) import mat ...
- C# 实现简单的 Heap 堆(二叉堆)
如题,C# 实现简单的二叉堆的 Push() 和 Pop(), 如有不足欢迎指正. 另外,在C#中使用 Heap 的相似功能可以考虑使用:Priority Queues,SortedDictiona ...
- ros 启动launch文件,附带参数
roslaunch cartographer_ros cartographer_ref.launch resolution:=0.07 #下面是cartographer_ref.launch的内容 & ...
- JSON序列化反序列化
JSON(全称为JavaScript Object Notation) 是一种轻量级的数据交换格式.它是基于JavaScript语法标准的一个子集. JSON采用完全独立于语言的文本格式,可以很容易在 ...