链接: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.

输出描述:

  1. An integer, the minimum distance of the largest step.

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

-->

示例1

输入

  1. 6 3
  2. 1 3 2 2 5

输出

  1. 5
  2.  
  3. 题解:
    二分答案(好蠢啊)
  1. /*
  2. data:2018.5.22
  3. author:gsw
  4. link:https://www.nowcoder.com/acm/contest/106/K
  5. */
  6. #define ll long long
  7. #define IO ios::sync_with_stdio(false);
  8.  
  9. #include<math.h>
  10. #include<stdio.h>
  11. #include<string.h>
  12. #include<iostream>
  13. #include<algorithm>
  14. using namespace std;
  15. #define maxn 100005
  16.  
  17. ll l,r,mid;
  18. int n,k;
  19. ll dis[maxn];
  20. bool judge(ll d)
  21. {
  22. ll tem=;int kk=;
  23. for(int i=;i<n-;i++)
  24. {
  25. if(dis[i]>d)return false;
  26. if(tem+dis[i]>d)
  27. {
  28. tem=dis[i];
  29. kk++;
  30. }
  31. else tem+=dis[i];
  32. }
  33. kk++;
  34. if(kk>k)return false;
  35. return true;
  36. }
  37. int main()
  38. {
  39. l=r=;
  40. scanf("%d%d",&n,&k);
  41. for(int i=;i<n-;i++)
  42. {
  43. scanf("%lld",&dis[i]);
  44. r+=dis[i];
  45. }ll mid=;
  46. while(l<r-)
  47. {
  48. mid=(l+r)>>;
  49. if(judge(mid))r=mid;
  50. else l=mid;
  51. }
  52. printf("%lld\n",r);
  53. return ;
  54. }
  1.  

第十四届华中科技大学程序设计竞赛 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. OC学习篇之---类目的概念和使用

    上一篇文章介绍了OC中的@class关键字的使用http://blog.csdn.net/jiangwei0910410003/article/details/41774747,这一篇我们介绍一下,O ...

  2. AcWing 229. 新NIM游戏 (线性基+博弈论)打卡

    题目:https://www.acwing.com/problem/content/description/231/ 题意:给出n堆石子,然后第一回合,A玩家可以随便拿多少堆石子,第二回合B玩家随便拿 ...

  3. centos6编译安装php7

    https://www.cnblogs.com/wenwei-blog/p/6261637.html https://www.cnblogs.com/imzye/p/5109770.html cent ...

  4. docker容器管理-含静态Ip(10)

    docker run命令详解 docker run -t #表示分配一个伪终端 -i #表示让容器的标准输入打开,不跟这个参数容器启不来 -d #后台运行 -P #dockerfile中EXPOSE ...

  5. API参考文档

    Android 中文版:http://www.apiref.com/android-zh/index.html Bootstrap3 教程:http://www.apiref.com/bootstra ...

  6. ANSI 标准C 还定义了如下几个宏

    ANSI 标准C 还定义了如下几个宏:_LINE_ 表示正在编译的文件的行号_FILE_ 表示正在编译的文件的名字预处理名称意义#define 宏定义#undef 撤销已定义过的宏名#include ...

  7. alerttemplate 时间戳转换

    /*时间戳转换*/ template.defaults.imports.dateFmt = function(ns){ return new Date(parseInt(ns)).toLocaleSt ...

  8. HashCode方法整理

    哈希表这个数据结构想必大多数人都不陌生,而且在很多地方都会利用到hash表来提高查找效率.在Java的Object类中有一个方法: 1 public native int hashCode(); 根据 ...

  9. PAT甲级——A1148 WerewolfSimpleVersion【20】

    Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...

  10. 接口调用post请求参数在body中

    package com.ynhrm.common.utils; import com.alibaba.fastjson.JSONObject; import lombok.Data; import o ...