链接:https://www.nowcoder.com/acm/contest/106/K
来源:牛客网

题目描述

It’s universally acknowledged that there’re innumerable trees in the campus of HUST.
Now you're going to walk through a large forest. There is a path consisting of N stones winding its way to the other side of the forest. Between every two stones there is a distance. Let di indicates the distance between the stone i and i+1.Initially you stand at the first stone, and your target is the N-th stone. You must stand in a stone all the time, and you can stride over arbitrary number of stones in one step. If you stepped from the stone i to the stone j, you stride a span of (di+di+1+...+dj-1). But there is a limitation. You're so tired that you want to walk through the forest in no more than K steps. And to walk more comfortably, you have to minimize the distance of largest step.

输入描述:

The first line contains two integer N and K as described above.
Then the next line N-1 positive integer followed, indicating the distance between two adjacent stone.

输出描述:

An integer, the minimum distance of the largest step.

输入例子:
6 3
1 3 2 2 5
输出例子:
5

-->

示例1

输入

6 3
1 3 2 2 5

输出

5

题解:
二分答案(好蠢啊)
/*
data:2018.5.22
author:gsw
link:https://www.nowcoder.com/acm/contest/106/K
*/
#define ll long long
#define IO ios::sync_with_stdio(false); #include<math.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 100005 ll l,r,mid;
int n,k;
ll dis[maxn];
bool judge(ll d)
{
ll tem=;int kk=;
for(int i=;i<n-;i++)
{
if(dis[i]>d)return false;
if(tem+dis[i]>d)
{
tem=dis[i];
kk++;
}
else tem+=dis[i];
}
kk++;
if(kk>k)return false;
return true;
}
int main()
{
l=r=;
scanf("%d%d",&n,&k);
for(int i=;i<n-;i++)
{
scanf("%lld",&dis[i]);
r+=dis[i];
}ll mid=;
while(l<r-)
{
mid=(l+r)>>;
if(judge(mid))r=mid;
else l=mid;
}
printf("%lld\n",r);
return ;
}

第十四届华中科技大学程序设计竞赛 K--Walking in the Forest的更多相关文章

  1. 第十四届华中科技大学程序设计竞赛 K Walking in the Forest【二分答案/最小化最大值】

    链接:https://www.nowcoder.com/acm/contest/106/K 来源:牛客网 题目描述 It's universally acknowledged that there'r ...

  2. 第十四届华中科技大学程序设计竞赛 C Professional Manager【并查集删除/虚点】

    题目描述 It's universally acknowledged that there're innumerable trees in the campus of HUST. Thus a pro ...

  3. 第十四届华中科技大学程序设计竞赛决赛同步赛 A - Beauty of Trees

    A - Beauty of Trees 题意: 链接:https://www.nowcoder.com/acm/contest/119/A来源:牛客网 Beauty of Trees 时间限制:C/C ...

  4. 第十四届华中科技大学程序设计竞赛决赛同步赛 F Beautiful Land(01背包,背包体积超大时)

    链接:https://www.nowcoder.com/acm/contest/119/F来源:牛客网 Beautiful Land 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1 ...

  5. 第十四届华中科技大学程序设计竞赛 J Various Tree【数值型一维BFS/最小步数】

    链接:https://www.nowcoder.com/acm/contest/106/J 来源:牛客网 题目描述 It's universally acknowledged that there'r ...

  6. 第十四届华中科技大学程序设计竞赛 B Beautiful Trees Cutting【组合数学/费马小定理求逆元/快速幂】

    链接:https://www.nowcoder.com/acm/contest/106/B 来源:牛客网 题目描述 It's universally acknowledged that there'r ...

  7. 第十四届华中科技大学程序设计竞赛决赛同步赛 Beautiful Land

    It’s universally acknowledged that there’re innumerable trees in the campus of HUST.Now HUST got a b ...

  8. 第十四届华中科技大学程序设计竞赛--J Various Tree

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

  9. Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again

    Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again https://ac.nowcoder.com/acm/contest/700/I 时间限制:C/C++ 1 ...

随机推荐

  1. zabbix 如何监控php-fpm?

    zabbix监控php-fpm主要是通过nginx配置php-fpm的状态输出页面,在正则取值.要nginx能输出php-fpm的状态首先要先修改php-fpm的配置,没有开启nginx是没有法输出p ...

  2. 左闭右开线段树 2019牛客多校(第七场)E_Find the median(点代表区间

    目录 题意 一种解析 AC_Code @(2019第七场牛客 E_Find the median 左闭右开线段树) 题意 链接:here 我理解的题意就是:初始序列为空,有\(n(400000)\)次 ...

  3. 并口、串口、COM口区别

          并行接口,简称并口.并口采用的是25针D形接头.所谓“并行”,是指8位数据同时通过并行线进行传送,这样数据传送速度大大提高,但并行传送的线路长度受到限制,因为长度增加,干扰就会增加,数据也 ...

  4. IOS 基于APNS消息推(JAVA后台)

    直接上Demo import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.StringUti ...

  5. centos python3.7 报错 No module named ‘_ctypes’ make: ***

    1.先装好python的依赖 2.yum install libffi-devel -y(解决)

  6. PHP 图片裁切

    PHP CLASS TO CREATE IMAGE THUMBANILS Some years ago, I wrote a PHP class to create image thumbnails ...

  7. SQL才是世界上最牛逼的语言!

    身处互联网行业,SQL 可能是你需要掌握的核心技能之一. 最早的时候,SQL 作为一门查询数据库的语言,是程序员的必备技能,运维.开发.Web 以及数据等从业人员都需要用到 SQL,毕竟只有查询到正确 ...

  8. Python之循环遍历

    range() 快输生成序列 利用 items()提取字典元素 在Python里,for循环后面是可以接一个else 的,在for循环正常结束时候,else 语句会被执行(while循环也是一样哦), ...

  9. hbuilder模拟器端口

    模拟器 | 端口 夜神安卓模拟器夜神安卓模拟器     62001 逍遥安卓模拟器逍遥安卓模拟器     21503 BlueStacks(蓝叠安卓模拟器)BlueStacks(蓝叠安卓模拟器)    ...

  10. react 小技巧

    1.当从redux里异步获取数据时,在render里渲染dom会出现数据还未获取到的情况,这时可以用 usableSchemas.data.vertexes && usableSche ...