第十四届华中科技大学程序设计竞赛 K--Walking in the Forest
链接:https://www.nowcoder.com/acm/contest/106/K
来源:牛客网
题目描述
输入描述:
输出描述:
An integer, the minimum distance of the largest step.
输入例子:
6 3
1 3 2 2 5
输出例子:
5
-->
输入
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的更多相关文章
- 第十四届华中科技大学程序设计竞赛 K Walking in the Forest【二分答案/最小化最大值】
链接:https://www.nowcoder.com/acm/contest/106/K 来源:牛客网 题目描述 It's universally acknowledged that there'r ...
- 第十四届华中科技大学程序设计竞赛 C Professional Manager【并查集删除/虚点】
题目描述 It's universally acknowledged that there're innumerable trees in the campus of HUST. Thus a pro ...
- 第十四届华中科技大学程序设计竞赛决赛同步赛 A - Beauty of Trees
A - Beauty of Trees 题意: 链接:https://www.nowcoder.com/acm/contest/119/A来源:牛客网 Beauty of Trees 时间限制:C/C ...
- 第十四届华中科技大学程序设计竞赛决赛同步赛 F Beautiful Land(01背包,背包体积超大时)
链接:https://www.nowcoder.com/acm/contest/119/F来源:牛客网 Beautiful Land 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1 ...
- 第十四届华中科技大学程序设计竞赛 J Various Tree【数值型一维BFS/最小步数】
链接:https://www.nowcoder.com/acm/contest/106/J 来源:牛客网 题目描述 It's universally acknowledged that there'r ...
- 第十四届华中科技大学程序设计竞赛 B Beautiful Trees Cutting【组合数学/费马小定理求逆元/快速幂】
链接:https://www.nowcoder.com/acm/contest/106/B 来源:牛客网 题目描述 It's universally acknowledged that there'r ...
- 第十四届华中科技大学程序设计竞赛决赛同步赛 Beautiful Land
It’s universally acknowledged that there’re innumerable trees in the campus of HUST.Now HUST got a b ...
- 第十四届华中科技大学程序设计竞赛--J Various Tree
链接:https://www.nowcoder.com/acm/contest/106/J来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...
- Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again
Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again https://ac.nowcoder.com/acm/contest/700/I 时间限制:C/C++ 1 ...
随机推荐
- python 的按位与、或、异或 运算
符号 描述 运算规则 by MoreWindows & 与 两个位都为1时,结果才为1 (统计奇数) | 或 两个位都为0时,结果才为0 ...
- 2的N次方求解-----C++
2的N次方求解,一般情况如果不超出C/C++基本数据类型的表达范围,这个问题及其容易,但是如果N的值十分的大,以致于超出基本数据类型表达范围 下面的程序正是解决2的N次方这个大数精确求解的源码 #in ...
- Webx.0-Web4.0:Web4.0
ylbtech-Webx.0-Web4.0:Web4.0 Web系统是人类迄今最伟大的发明之一,也是计算机影响人类最深远的表现. 1.返回顶部 1. Web系统是人类迄今最伟大的发明之一,也是计算机影 ...
- Python错误 importModuleNotFoundError: No module named 'Crypto'
0x00经过 今天在python中导入模块的用 from Crypto.Cipher import AES 的时候出现了找不到模块的错误. 百度了很长时间有很多解决方法,但是因不同的环境不同的 ...
- SPSS输出的结果都要写到文章中吗
SPSS输出的结果都要写到文章中吗 经常有人问到,SPSS输出的结果都要写到文章中吗?文章中应该写什么呢?比如,均值.中位数.众数.标准差.百分位数.最小值.最大值等等,都要出现在文章中吗?洋洋洒洒那 ...
- 洛谷P1629 邮递员送信 最短路-Djistra
先上一波题目qwq https://www.luogu.org/problem/P1629· 复习了一波 dijstra 的 priority_queue(优先队列)优化的写法 tips: 求单项路中 ...
- shell getopts命令
由于shell命令行的灵活性,自己编写代码判断时,复杂度会比较高.使用内部命令 getopts 可以很方便地处理命令行参数.一般格式为: getopts optstring name [args] ...
- Scrapy框架: pipelines.py设置
保存数据到json文件 # -*- coding: utf-8 -*- # Define your item pipelines here # # Don't forget to add your p ...
- 廖雪峰的git学习笔记
安装完后,每个机器都要自报家门 Config--配置 global--全局参数 配置全局用户名 $git config --global user.name “Your Name” 配置邮箱 ...
- JSP界面引用百度地图获取坐标
需求: 需要在JSP界面上引用百度地图,文本框中输入地址之后,自动拿到在百度地图上的经纬度 解决步骤: 1.引入百度地图api: head中进行引用<script type="text ...