枚举,三分。

首先,这$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. ASP.NET-FineUI开发

    ASP.NET-FineUI开发 随笔分类 - FineUI   ASP.NET-FineUI开发实践-10 摘要: 嵌套Grid,光棍月大放送,不藏着掖着.实在写的不好,没脸藏啊~只考虑显示排序修改 ...

  2. 如何使用OPENQUERY访问另一个SQL Server

    原文:如何使用OPENQUERY访问另一个SQL Server 在项目中,经常会遇到一个数据库访问另一个数据库,[CNVFERPDB]为服务器名,[CE3]为库名 SELECT Dtl.* FROM ...

  3. PHP+MYSQL分页原理

    1.SQL语句中的limit用法 2.学习分页的一种公式 3.parse_url()解析URL函数 parse_url() 是将URL解析成有固定键值的数组的函数 4.$_SERVER["R ...

  4. mvc项目如何在IIS7.5

    mvc项目如何在IIS7.5上发布的 1.在vs中打开你要发布的项目,右键属性找到发布 2.弹出发布web对话框,选择<新建配置文件...> 在弹出的对话框中输入一个配置文件名称,后确定 ...

  5. hadoop集群的搭建与配置(1)

    前言             首先hadoop是在linux系统上进行搭建的,我们首先要在自己电脑上装上虚拟机然后装linux系统,因为我们是测试:在本地虚拟机上装两个linux分别搭建好hadoop ...

  6. [Usaco2008 Feb]Meteor Shower流星雨[BFS]

    Description 去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽, 届时将会对它撞到的 ...

  7. YARN

    YARN 介绍 Apache Hadoop YARN作为hadoop的子项目加入到Hadoop Common (core libraries), Hadoop HDFS (storage) and H ...

  8. Oracle 10g的空间管理

    一.表空间(包含表.字段.索引) 1.定义:表空间是一个逻辑概念,实质是组织数据文件的一种途径. 2.创建表空间 --创建表空间 create tablespace myspace datafile ...

  9. DevExpress 学习使用之 NavBarControl

    TNND,没辙啊,没用过那么高级的玩意儿,暂时也没找到中文的详细帮助,简直就是蚂蚁搬家似的摸索,一点儿点儿来吧. 先是NavBarControl的界面样子,貌似可以通过 PaintStyleKind ...

  10. ASP.NET MVC企业开发的基本环境

    ASP.NET MVC企业开发的基本环境[资源服务器概念] 学完了ASP.NET MVC4 IN ACTION 六波以后 企业开发演习 标签:AaronYang  茗洋  EasyUI1.3.4   ...