第十四届华中科技大学程序设计竞赛 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 ...
随机推荐
- OC学习篇之---类目的概念和使用
上一篇文章介绍了OC中的@class关键字的使用http://blog.csdn.net/jiangwei0910410003/article/details/41774747,这一篇我们介绍一下,O ...
- AcWing 229. 新NIM游戏 (线性基+博弈论)打卡
题目:https://www.acwing.com/problem/content/description/231/ 题意:给出n堆石子,然后第一回合,A玩家可以随便拿多少堆石子,第二回合B玩家随便拿 ...
- centos6编译安装php7
https://www.cnblogs.com/wenwei-blog/p/6261637.html https://www.cnblogs.com/imzye/p/5109770.html cent ...
- docker容器管理-含静态Ip(10)
docker run命令详解 docker run -t #表示分配一个伪终端 -i #表示让容器的标准输入打开,不跟这个参数容器启不来 -d #后台运行 -P #dockerfile中EXPOSE ...
- API参考文档
Android 中文版:http://www.apiref.com/android-zh/index.html Bootstrap3 教程:http://www.apiref.com/bootstra ...
- ANSI 标准C 还定义了如下几个宏
ANSI 标准C 还定义了如下几个宏:_LINE_ 表示正在编译的文件的行号_FILE_ 表示正在编译的文件的名字预处理名称意义#define 宏定义#undef 撤销已定义过的宏名#include ...
- alerttemplate 时间戳转换
/*时间戳转换*/ template.defaults.imports.dateFmt = function(ns){ return new Date(parseInt(ns)).toLocaleSt ...
- HashCode方法整理
哈希表这个数据结构想必大多数人都不陌生,而且在很多地方都会利用到hash表来提高查找效率.在Java的Object类中有一个方法: 1 public native int hashCode(); 根据 ...
- PAT甲级——A1148 WerewolfSimpleVersion【20】
Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...
- 接口调用post请求参数在body中
package com.ynhrm.common.utils; import com.alibaba.fastjson.JSONObject; import lombok.Data; import o ...