枚举,三分。

首先,这$n+1$个人一定是连续的放在一起的。可以枚举每一个起点$L$,然后就是在$[L,R]$中找到一个位置$p$,使得$p4最优,因为越往两边靠,距离就越大,在中间某位置取到最优解,所以三分一下就可以了。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} const int maxn=;
int n,k,p[maxn],sz;
char s[maxn]; int get(int x,int low,int high)
{
return max(p[x]-p[low],p[high]-p[x]);
} int f(int L,int R)
{
int t1,t2; int low=L,high=R;
for(int i=;i<=;i++)
{
t1=(low+high)/;
t2=(t1+high)/;
if (get(t1,L,R)<get(t2,L,R)) high=t2;
else low=t1;
}
return get(t1,L,R);
} int main()
{
scanf("%d%d",&n,&k);
scanf("%s",s);
for(int i=;s[i];i++)
{
if(s[i]=='') continue;
sz++; p[sz]=i+;
} int ans=;
for(int i=;i<=sz;i++)
{
if(i+k>sz) break;
ans=min(ans,f(i,i+k));
}
printf("%d\n",ans);
return ;
}

CodeForces 645C Enduring Exodus的更多相关文章

  1. Codeforces 645C Enduring Exodus【二分】

    题目链接: http://codeforces.com/contest/645/problem/C 题意: 给定01串,将k头牛和农夫放进, 0表示可以放进,1表示不可放进,求农夫距离其牛的最大距离的 ...

  2. codeforces 645C . Enduring Exodus 三分

    题目链接 我们将所有为0的位置的下标存起来. 然后我们枚举左端点i, 那么i+k就是右端点. 然后我们三分John的位置, 找到下标为i时的最小值. 复杂度 $ O(nlogn) $ #include ...

  3. Code Forces 645C Enduring Exodus

    C. Enduring Exodus time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...

  4. codeforces 655C C. Enduring Exodus(二分)

    题目链接: C. Enduring Exodus time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

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

  6. Enduring Exodus CodeForces - 655C (二分)

    链接 大意: n个房间, 1为占用, 0为未占用, John要将k头奶牛和自己分进k+1个空房间, 求John距最远的奶牛距离的最小值 这种简单题卡了20min.... 显然对于固定的k+1个房间, ...

  7. CodeForces - 645 C.Enduring Exodus

    快乐二分 用前缀和随便搞一下 #include <cstdio> using namespace std; ; int p[N]; ; inline int msum(int a, int ...

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

随机推荐

  1. 实用的两款jquery树形tree插件

    这里有两款非常实用的jquery tree控件: (1) ------------------------------------------1.(根据一讲师总结) ---zTree: jquery. ...

  2. oracle实例,数据库,服务器区别

    实例(instance) 实例是一个非固定的,基于内存的基本进程与内存结构.当服务器关闭时,实例就不存在了. 数据库(DataBase) 数据库指固定的,基于磁盘的数据文件,控制文件,日志文件,参数文 ...

  3. U盘安装Win7

    声明:本方法仅仅适用于windows 7 的安装. 工具准备: 1.网上下载一个windows 7 系统.最好是纯净版的,非Gost 版.虽然装机慢了一些,但到用时就体会到他的流畅. 2.Window ...

  4. 6 MySQL视图

    目录: 1. 视图概述 1.1 为什么引入视图 1.2 什么是视图 1.3 视图的好处 1.4 视图的分类 2. 视图的建立和删除 3. 实验 1. 视图概述 1.1 为什么引入视图[1] 问题:假如 ...

  5. .NET核心代码保护策略

    .NET核心代码保护策略-隐藏核心程序集 经过之前那个道德指责风波过后也有一段时间没写博客了,当然不是我心怀内疚才这么久不写,纯粹是程序员的通病..怎一个懒字了得,本来想写一些长篇大论反讽一下那些道德 ...

  6. 应用程序入口 WSGIHandler

    Django 源码小剖: 应用程序入口 WSGIHandler WSGI 有三个部分, 分别为服务器(server), 应用程序(application) 和中间件(middleware). 已经知道 ...

  7. hive left outer join的问题

    最近BA用户反馈有两句看似很像的语句返回的结果数不一样,比较奇怪,怀疑是不是Hive的Bug Query 1 返回结果数6071 select count(distinct reviewid) as ...

  8. jQuery Colorbox是一款弹出层

    jQuery Colorbox使用教程 jQuery Colorbox是一款弹出层,内容播放插件,效果极佳,最关键的是大小只有10KB,当然我主要是用来弹出图片啦,(之前介绍过jquery Fancy ...

  9. window.parent与window.opener的区别

    有这样一个需求,弹出一个新窗口 并从该新页面的select选择框中选择需要的类别,再返回到之前的父窗口页面的某个文本框中.这里就要用到window.parent和window.opener 如题两种方 ...

  10. Java快速开发工具 WebBuilder 6.8发布

    WebBuilder是一款开源的可视化Java Web应用开发和运行平台: 基于浏览器的集成开发环境,可视化和智能化的设计,能轻松完成常规应用和面向手机的移动应用开发: 高效.稳定和可扩展的特点,适合 ...