博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第十四届华中科技大学程序设计竞赛 K--Walking in the Forest
阅读量:4451 次
发布时间:2019-06-07

本文共 1890 字,大约阅读时间需要 6 分钟。

链接:

来源:牛客网

题目描述

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 d
i 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 (d
i+d
i+1+...+d
j-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.
示例1

输入

6 31 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
#include
#include
#include
#include
using namespace std;#define maxn 100005ll l,r,mid;int n,k;ll dis[maxn];bool judge(ll d){ ll tem=0;int kk=0; for(int i=0;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=0; scanf("%d%d",&n,&k); for(int i=0;i
>1; if(judge(mid))r=mid; else l=mid; } printf("%lld\n",r); return 0;}

 

 

转载于:https://www.cnblogs.com/fantastic123/p/9074339.html

你可能感兴趣的文章
jQuery 停止动画
查看>>
Sharepoint Solution Gallery Active Solution时激活按钮灰色不可用的解决方法
查看>>
MyBatis Generator去掉生成的注解
查看>>
教你50招提升ASP.NET性能(二十二):利用.NET 4.5异步结构
查看>>
lua连续随机数
查看>>
checkstyle使用介绍
查看>>
history.js 一个无刷新就可改变浏览器栏地址的插件(不依赖jquery)
查看>>
会了这十种Python优雅的写法,让你工作效率翻十倍,一人顶十人用!
查看>>
二维码图片生成
查看>>
在做操作系统实验的一些疑问
查看>>
Log4J日志配置详解
查看>>
NameNode 与 SecondaryNameNode 的工作机制
查看>>
Code obfuscation
查看>>
大厂资深面试官 带你破解Android高级面试
查看>>
node.js系列(实例):原生node.js实现接收前台post请求提交数据
查看>>
SignalR主动通知订阅者示例
查看>>
golang的表格驱动测试
查看>>
用python实现矩阵转置
查看>>
linux 小技巧(磁盘空间搜索)
查看>>
iOS开发——捕获崩溃信息
查看>>