CodeForces 645C Enduring Exodus
枚举,三分。
首先,这$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的更多相关文章
- Codeforces 645C Enduring Exodus【二分】
题目链接: http://codeforces.com/contest/645/problem/C 题意: 给定01串,将k头牛和农夫放进, 0表示可以放进,1表示不可放进,求农夫距离其牛的最大距离的 ...
- codeforces 645C . Enduring Exodus 三分
题目链接 我们将所有为0的位置的下标存起来. 然后我们枚举左端点i, 那么i+k就是右端点. 然后我们三分John的位置, 找到下标为i时的最小值. 复杂度 $ O(nlogn) $ #include ...
- Code Forces 645C Enduring Exodus
C. Enduring Exodus time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...
- 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 ...
- Enduring Exodus CodeForces - 655C (二分)
链接 大意: n个房间, 1为占用, 0为未占用, John要将k头奶牛和自己分进k+1个空房间, 求John距最远的奶牛距离的最小值 这种简单题卡了20min.... 显然对于固定的k+1个房间, ...
- CodeForces - 645 C.Enduring Exodus
快乐二分 用前缀和随便搞一下 #include <cstdio> using namespace std; ; int p[N]; ; inline int msum(int a, int ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- VMWare 11安装操作系统 - 初学者系列 - 学习者系列文章
在2010年的时候,我写过一篇关于VMWare的安装操作系统的博文.但是今天在QQ群里有人问起VMWare安装操作系统的问题,虽然回答了,但是回头看了下当时那篇博文,决定重新写一文. 首先要获取VMW ...
- PLSQL导入/导出数据方法
PLSQL导入/导出数据方法 PLSQL导入/导出数据方法 以前导数据库信息的时候,总是会先开启sql窗口,把自己手写的建表文件复制进去,然后再导入数据信息. 今天突然懒得去找以前的建表文件,而想用S ...
- Metro UI 界面完全解析 (转载)
Metro在微软的内部开发名称为“ typography-based design language”(基于排版的设计语言).它最早出现在微软电子百科全书95,此后微软又有许多知名产品使用了Metro ...
- less 命令
每天一个linux命令(13):less 命令 less 工 具也是对文件或其它输出进行分页显示的工具,应该说是linux正统查看文件内容的工具,功能极其强大.less 的用法比起 more 更加的有 ...
- Android开发方法学
这是Cyril Mottier最近更新的一篇文章,原谅地址在这里:Android开发方法学. 这篇文章是他介绍自己所在项目小组(Capitaine Train Android Team)设计.开发时的 ...
- Effective C++(13) 用对象管理资源
问题聚焦: 从这条准则开始,都是关于资源管理的. 资源,一旦用了它,将来必须还给系统. 本条准则,基于对象的资源管理办法,建立在C++的构造函数,析构函数和拷贝函数(拷贝构造函数和重载赋值操作符)的基 ...
- 增删查改-MySQL
查询: 在MySQL中,select的基本语法形式: select 属性列表 from 表名和视图 [where 条件表达式] [group by 属性名 [having 条件表达式]] [order ...
- require.js实践
ASP.NET MVC应用require.js实践 这里有更好的阅读体验和及时的更新:http://pchou.info/javascript/asp.net/2013/11/10/527f6ec41 ...
- C/C++基础知识总结——函数
1. 随机函数的使用 1.1 头文件: # include <cstdlib> 或 # include <stdlib.h> 1.2 用法 srand(int seed);// ...
- 如何将 Area 中的 Controller 放到独立的程序集?
目录 背景如何将 Area 中的 Controller 放到独立的程序集?备注 背景返回目录 本文假设您已经熟悉了 ASP.NET MVC 的常规开发方式.执行模型和关键扩展点,这里主要说一下如何使用 ...