第十四届华中科技大学程序设计竞赛 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 ...
随机推荐
- paper 135:关于C#泛型的知识点
计划着要用一个月的时间把 C#语言Windows程序设计 搞定,现在是零零散散的知识点,日积月累吧!朋友们,看这里咯~呵呵 原文地址:http://www.blogjava.net/Jack2007 ...
- 饿了么 <el-input></el-input>输入框获取与失去焦点事件
//1.定义focus事,绑定属性 <el-input v-model="headerInput" @focus="onInputFocus" @blur ...
- Java奇葩笔试题
1.下面代码中,在if处填写什么代码,可以使得输出结果为:AB 1 2 3 4 5 6 7 8 9 public static void main(String[] args) { if ( ){// ...
- 框架-.NET:.NET Core
ylbtech-框架-.NET:.NET Core .NET Core是适用于 windows.linux 和 macos 操作系统的免费.开源托管的计算机软件框架,是微软开发的第一个官方版本,具有跨 ...
- 64、通过PickListValuesUtil,Schema查看下拉列表中的值
public class PickListValuesUtil { public static Map<String,Object> getPicklistValues(String sO ...
- 用 Flask 来写个轻博客 (13) — M(V)C_WTForms 服务端表单检验
目录 目录 前文列表 WTForms WTF 的基础使用 常用的字段类型 fieldsDateField fieldsIntegerField fieldsFloatField fieldsStrin ...
- Django框架(二十)—— Django rest_framework-认证组件
目录 Django rest_framework-认证组件 一.什么是认证 二.利用token记录认证过的用户 1.什么是token 2.token的原理 3.cookie.session.token ...
- 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 ...
- Head First PHP &MySQL学习笔记
最近一段时间在学习PHP,买了<Head First PHP&MySQL>中文版这本书,之前买过<Head First设计模式>,感觉这系列的书籍总体来说很不错. ...
- 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 ...