第十四届华中科技大学程序设计竞赛kwalkingintheforest二分答案/最小化最大值(代码片段)

Roni Roni     2022-11-07     778

关键词:

链接: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.
输出描述:
An integer, the minimum distance of the largest step.
示例1
输入
6 3
1 3 2 2 5
输出
5

【题意】:
题意就是说有n块石头,每块石头中间有一定的距离,一次可以跳过多个石头,但是不可以超过k步,求最大步的最小值 。

其实意思就是说,如果你每一步比较小,比如一块一块石头地过去,那么步数就太多了;但是如果你直接一步跳到最后,这样又太浪费体力了,而且不符合题意,而题意就是要你找到这么一个平衡点,可以恰好走到三步,然后求其中最大的一步的距离(相对于其他两步是最大的,但相对于所有情况的最大步它是最小的一种情况)

【出处】:POJ 3272 Monthly Expense

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;
#define ll long long
#define mod 1000000007
int n, k;
ll a[100005];
int main() 
    scanf("%d%d", &n, &k);
        ll s = 0;
        ll Max = 0;
        for (int i = 1; i <= n - 1; ++i) 
            scanf("%lld", &a[i]);
            s += a[i];
            Max = max(Max, a[i]);
        
        ll l = Max, r = s, ans, mid;
        while (l <= r) 
            mid = (l + r) >> 1;
            s = 0;
            int c = 0;
            for (int i = 1; i <= n - 1; ++i) 
                s += a[i];
                if (s > mid)    //多个跳不过,只能前面算跳一次,从这里重新开始跳
                    s = a[i];
                    c++;
                
            

            if (c >= k) 
                l = mid + 1;
            
            else 
                r = mid - 1;
                ans = mid;
            
        
        cout << ans << endl;
    return 0;

第十四届华中科技大学程序设计竞赛--jvarioustree(代码片段)

链接:https://www.nowcoder.com/acm/contest/106/J来源:牛客网时间限制:C/C++1秒,其他语言2秒空间限制:C/C++32768K,其他语言65536K64bitIOFormat:%lld题目描述It’suniversallyacknowledgedthatthere’reinnumerabletreesinthecampusofH 查看详情

第十四届华中科技大学程序设计竞赛cprofessionalmanager并查集删除/虚点(代码片段)

题目描述It’suniversallyacknowledgedthatthere’reinnumerabletreesinthecampusofHUST.Thusaprofessionaltreemanagerisneeded.Yourtaskistowriteaprogramtohelpmanagethetrees.Initially,therearenforestsandforthei-thf 查看详情

第十四届全国大学生智能车竞赛竞赛技术报告下载链接

第十四届智能车竞赛技术报告下载链接 01下载报告  今天上午,看到有同学询问关于十四届智能车竞赛技术报告下载的询问。 实际上,之前第十四届的技术报告在百度上有, 只是没有能够提供下载链接。 由... 查看详情

第十四届华中科技大学程序设计竞赛jvarioustree数值型一维bfs/最小步数(代码片段)

链接:https://www.nowcoder.com/acm/contest/106/J来源:牛客网题目描述It’suniversallyacknowledgedthatthere’reinnumerabletreesinthecampusofHUST.AndtherearemanydifferenttypesoftreesinHUST,eachofwhichhasanumberrepresen 查看详情

浙江财经大学第十四届程序设计竞赛题解

 【题面pdf下载】链接:https://pan.baidu.com/s/1Eb16fHtNYMLrRk9QnXWa-g密码:dwn8【题目牛客网提交链接】【现场赛排名】链接:https://pan.baidu.com/s/1jfzH6-7BoPhEjnijGQK53w密码:y669 感谢各位大佬的参赛。 由于命题人水平不高,而且之前没... 查看详情

第十四届华中科技大学程序设计竞赛kwalkingintheforest二分答案/最小化最大值(代码片段)

链接:https://www.nowcoder.com/acm/contest/106/K来源:牛客网题目描述It’suniversallyacknowledgedthatthere’reinnumerabletreesinthecampusofHUST.Nowyou'regoingtowalkthroughalargeforest.ThereisapathconsistingofNsto 查看详情

长春理工大学第十四届程序设计竞赛(重现赛)m.orxzone

链接:https://ac.nowcoder.com/acm/contest/912/M题意:DaenerysStormborn,风暴中出生的丹尼莉丝,theUnburnt,烧不死的,QueenofMeereen,弥林女王,QueenoftheAndalsandtheRhoynarandtheFirstMen,安达尔人,罗伊那人,和先民的女王,LordoftheSevenKingdoms,七国之主 查看详情

长春理工大学第十四届程序设计竞赛(重现赛)h

H.ArithmeticSequence题目链接:https://ac.nowcoder.com/acm/contest/912/H题目数竞选手小r最喜欢做的题型是数列大题,并且每一道都能得到满分。你可能不相信,但其实他发现了一个结论:只要是数列,无论是给了通项还是给了递推式,无论... 查看详情

长春理工大学第十四届程序设计竞赛(重现赛)f(代码片段)

F.SuccessionediFixoracci题目链接:https://ac.nowcoder.com/acm/contest/912/F 题目:动态规划(Dynamicprogramming,简称dp)是一种通过把原问题分解为相对简单的子问题的方式求解复杂问题的方法。例如,假设小x一步能爬1层或2层台阶,求小x爬n... 查看详情

长春理工大学第十四届程序设计竞赛(重现赛)b(代码片段)

BBowlingGame题目链接:https://ac.nowcoder.com/acm/contest/912/B题目CUST的队员打完省赛后,小r带着大家去打保龄球。保龄球是一项难度非常高的游戏,然而这根本难不住校队成员,他们个个都很厉害(炸和)一发10个瓶都倒。尤其是小r,每次... 查看详情

长春理工大学第十四届程序设计竞赛(重现赛)j.printout

链接:https://ac.nowcoder.com/acm/contest/912/J题意:小r为了打校赛,他打算去打字社打印一份包含世界上所有算法的模板。到了打字社,小r一看价格:总打印页数X0X0页以下(不含X0X0)x0x0元每页,X0∼X1X0∼X1页(不含X1X1)x1x1元每页,X1&si... 查看详情

hdu6467简单数学题递推公式&&o优化乘法(广东工业大学第十四届程序设计竞赛)(代码片段)

...rce“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛        解题思路: 但是这道题只推出递推 查看详情

广东工业大学第十四届程序设计竞赛鸽子数(代码片段)

ProblemDescription通常来说,题面短的题目一般都比较难,所以我要把题面写得很长很长。通常来说,题面短的题目一般都比较难,所以我要把题面写得很长很长。通常来说,题面短的题目一般都比较难,所以我要把题面写得很长很... 查看详情

(未完成)[hduoj]“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛(代码片段)

solved5 A(签到)题意:两个人随机得到0或1其中之一数字,每个人都可以猜对方的数字是什么,有一个人猜对就算成功,问最优策略下00,01,10,11四种情况两人的成功概率分别是多少。题意不明的签到题,题面说两人不能沟通... 查看详情

湖南大学第十四届acm程序设计新生杯e.easyproblem(代码片段)

E.EasyProblemDescription:Zghhlikesnumber,buthedoesn‘tlikewritingproblemdescription.Sohewilljustgiveyouaprobleminsteadoftellingalongstoryforit.Nowgivenapositiveintegerxandkdigitsa1,a2,...,ak,canyoufindapositiveintegerysuchthatyisthemultipleofxandindecimalrepresentationycontainsalldigitsofa1,a2,...,... 查看详情

第五届湖南省机器人大赛暨第十四届湖南省智能汽车大赛名单(代码片段)

简介:本文汇总了第五届湖南省智能车竞赛的基本信息。感谢中南大学王击老师发送过来的信息。关键词:湖南省智能车竞赛,智能车竞赛#mermaid-svg-Bl4gxd2xsRwJqsTIfont-family:"trebuchetms",verdana,arial,sans-serif;font-size:16px;fill:#3... 查看详情

第十四届蓝桥杯(web应用开发)模拟赛1期-大学组(代码片段)

数据类型检测请看这篇数据类型检测渐变色背景生成器html<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><metahttp-equiv="X-UA-Compatible"content="IE 查看详情

第十四届蓝桥杯c/c++_大学b组省赛真题

...或其它方式提交的答案无效。试题包含“结果填空”和“程序设计”两种题型。结果填空题:要求选手根据题目描述直接填写结果。求解方式不限。不要求源代码。把结果填空的答案直接通过网页提交即可,不要书写多... 查看详情