链接: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. paper 135:关于C#泛型的知识点

    计划着要用一个月的时间把  C#语言Windows程序设计 搞定,现在是零零散散的知识点,日积月累吧!朋友们,看这里咯~呵呵 原文地址:http://www.blogjava.net/Jack2007 ...

  2. 饿了么 <el-input></el-input>输入框获取与失去焦点事件

    //1.定义focus事,绑定属性 <el-input v-model="headerInput" @focus="onInputFocus" @blur ...

  3. Java奇葩笔试题

    1.下面代码中,在if处填写什么代码,可以使得输出结果为:AB 1 2 3 4 5 6 7 8 9 public static void main(String[] args) { if ( ){// ...

  4. 框架-.NET:.NET Core

    ylbtech-框架-.NET:.NET Core .NET Core是适用于 windows.linux 和 macos 操作系统的免费.开源托管的计算机软件框架,是微软开发的第一个官方版本,具有跨 ...

  5. 64、通过PickListValuesUtil,Schema查看下拉列表中的值

    public class PickListValuesUtil { public static Map<String,Object> getPicklistValues(String sO ...

  6. 用 Flask 来写个轻博客 (13) — M(V)C_WTForms 服务端表单检验

    目录 目录 前文列表 WTForms WTF 的基础使用 常用的字段类型 fieldsDateField fieldsIntegerField fieldsFloatField fieldsStrin ...

  7. Django框架(二十)—— Django rest_framework-认证组件

    目录 Django rest_framework-认证组件 一.什么是认证 二.利用token记录认证过的用户 1.什么是token 2.token的原理 3.cookie.session.token ...

  8. Java对象相等比较(Equals)

    以下代码显示如何实现equals()和hashCode()方法 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...

  9. Head First PHP &MySQL学习笔记

      最近一段时间在学习PHP,买了<Head First PHP&MySQL>中文版这本书,之前买过<Head First设计模式>,感觉这系列的书籍总体来说很不错. ...

  10. Optional int parameter 'pId' is present but cannot be translated into a null value due to being declared as a primitive type.

    接口测试的时候遇到了一个问题,导致测试阻断了好久,在此记录,谨防忘记. 具体报错如下: Optional int parameter 'pId' is present but cannot be tr ...