题意:给你一个二进制表示是否可以吃巧克力。一共有k个巧克力,第一天和最后一天必须吃。最小化每两次吃巧克力的最大间隔?

标程:

 #include<bits/stdc++.h>
using namespace std;
int read()
{
char ch=getchar();
while (ch<''||ch>'') ch=getchar();
while (''<=ch&&ch<='') return ch-'';
}
const int N=;
int n,k,a[N],head,pos,l,r,ans,num;
bool check(int x)
{
head=pos=;num=;
for (int i=;i<n;i++)
{
if (!a[i]) pos=i;
if (i==head+x+) {
if (pos==head) return ;
head=pos;num++;
}
}
return num+<=k;
}
int main()
{
scanf("%d%d",&n,&k);
for (int i=;i<=n;i++) a[i]=read();
l=;r=n;
while (l<=r)
{
int mid=(l+r)>>;
if (check(mid)) ans=mid,r=mid-;else l=mid+;
}
printf("%d\n",ans);
return ;
}

题解:二分答案

易错点:注意第一天和最后一天必须吃,特判一下。

CF774L Bars的更多相关文章

  1. PeopleSoft Rich Text Boxes上定制Tool Bars

      在使用PT8.50或在8.51时,你可能遇到过Rich-text编辑框.该插件使你能够格式化文本,添加颜色.链接.图片等等.下面是效果图: 如果页面中只有这么一个字段,该文本框就会有足够的空间来容 ...

  2. Android Immersive Mode (沉浸模式) 还是 Translucent Bars (透明状态栏)

    Immersive Mode (沉浸模式) 还是 Translucent Bars (透明状态栏) [科普]什么叫真正的“沉浸式”状态栏? 为什么在国内会有很多用户把「透明栏」(Translucent ...

  3. Plotting means and error bars (ggplot2)

    library(ggplot2) ############################################# # summarySE ######################### ...

  4. how to run demo city bars using sencha architect

    1. create a project using city bars template in sencha architect 2. save your project name as CityBa ...

  5. Search Bars(一个)

    A search bar provides an interface for text-based searches with a text box and buttons such as searc ...

  6. e-olymp Problem4196 Chocolate bars

    吐槽一下,这个OJ的题目真的是阅读理解题.代码非常短,就是题目难理解.心累. 传送门:点我 Chocolate bars It is hard to overestimate the role of ...

  7. Bars, rectangles with bases on x-axis

    Usage geom_bar(mapping = NULL, data = NULL, stat = "bin", position = "stack", .. ...

  8. 从零开始学ios开发(十一):Tab Bars和Pickers

    不好意思各位,本人休息了一个礼拜,所以这次的进度延后了,而且这次的学习的内容比较多,时间用的也比较长,文章发布的时间间隔有些长了,望各位谅解,下面继续我们的ios之旅. 这次我们主要学习的内容有2个, ...

  9. Some beautiful Progress Bars in WPF

    1.Better WPF Circular Progress Bar 2.Bending the WPF ProgressBar 3.A CIRCULAR PROGRESSBAR STYLE USIN ...

随机推荐

  1. [已解决]报错This event loop is already running

    安装nest_asyncio pip install nest_asyncio 导入并调用 import nest_asyncio nest_asyncio.apply()

  2. 2019牛客国庆集训派对day7 A 2016

    链接:https://ac.nowcoder.com/acm/problem/52800来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...

  3. vue中beforeRouteEnter 执行的时机及运用的误区?

    beforeRouteEnter钩子 beforeRouteEnter (to, from, next) { console.log(this); //undefined,不能用this来获取vue实 ...

  4. linux磁盘分区、挂载、查看

    实战: 34    查看本机所有磁盘                 fdisk -l 35    查看磁盘挂载情况                lsblk -f 36            39: ...

  5. c++ const (转)

    在C++的类定义里面,可以看到类似下面的定义: class List { private: Node * p_head; int length; …… Public: int GetLength () ...

  6. 笔记46 Hibernate快速入门(三)

    Hibernate相关概念 一.事物概念 Hibernate的任何对数据有改动的操作,都应该被放在事务里面. hibernate中的事务由s.beginTransaction();开始由s.getTr ...

  7. c 语言函数分析

    第一个参数为指向线程标识符的指针. 第二个参数用来设置线程属性. 第三个参数是线程运行函数的起始地址. 最后一个参数是运行函数的参数. result = pthread_create(&tid ...

  8. 使用Fiddler抓取手机包

    配置Fiddler 设置抓取HTTPS包 允许为外部连接 配置移动端 移动端需要能够连接到主机做代理, 设置移动端的网络, 端口为Fiddler的端口, 然后给移动端安装证书, 访问主机名+代理端口号 ...

  9. 判断访问浏览器客户端类型(pc,mac,ipad,iphone,android)

    <script type="text/javascript"> //平台.设备和操作系统 var system = { win: false, mac: false, ...

  10. HTML5布局篇

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title> ...