HDU 4004 The Frog's Games(二分)

C#多线程集合选型指南:ConcurrentDictionary与BlockingCollection实战 在多线程编程中,共享集合的并发访问是常见挑战。普通集合如List和Dictionary并非线程安全,多线程读写易导致数据丢失或异常。System.Collections.Concurrent命名空间提供了ConcurrentDictionary、ConcurrentQueue等线程安全集合,通过细粒度锁或无锁算法提升并发性能。合理选型可显著提高吞吐量,适用于缓存、生产者-消费者队列等场景。本文深入解析核心并发集合的内部原理、使用技巧及性能对比,助你避开常见陷阱。 阅读详情

Problem Description

The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over the river. The width of the river is L (1<= L <= 1000000000). There are n (0<= n <= 500000) stones lined up in a straight line from one side to the other side of the river. The frogs can only jump through the river, but they can land on the stones. If they fall into the river, they 
are out. The frogs was asked to jump at most m (1<= m <= n+1) times. Now the frogs want to know if they want to jump across the river, at least what ability should they have. (That is the frog's longest jump distance).

Input

The input contains several cases. The first line of each case contains three positive integer L, n, and m. 
Then n lines follow. Each stands for the distance from the starting banks to the nth stone, two stone appear in one place is impossible.

Output

For each case, output a integer standing for the frog's ability at least they should have.

Sample Input

6 1 2
2
25 3 3
11 
2
18

Sample Output

4
11
题意:河长L,有n个石子,青蛙最多跳m次,求跳到对岸青蛙最少一次要跳多少。

因为数据量是10^9,直接找1s会T,(1s处理数据量为10^6~10^7,撑死10^8),所以二分求跳跃距离(时间复杂度为logN);

用dis数组存储两个石子间的距离,然后从两石子间最大距离~L二分,直到left=right;

直接二分时mid是偏左的,所以修改左端点时mid+1;

求以x距离跳跃时步数,外循环i控制跳到哪一个dis,内循环j控制跳几个dis,一旦x<dis之和就steps++;

最后记得将i设置到即将要跳的dis,并且步数+1(因为求出来的i是到第n-1个dis);


做了好久的题啊……看了题解并没有理解最后还是自己一步一步模拟过程才懂的;

独立思考很重要!队友给了我很多提示,但是自己不把这个过程想明白永远都做不出来!


学会了新姿势system("pause")。。简直是我这种喜欢分析过程人的福音。。


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=500010;
int a[N];
int dis[N];
int L,n,m;
int jump(int x){
	int steps=0,i=1,j=0,sum=0;	
	while(i<n){
		sum=0;
		for(j=i;j<=n;j++){
			sum=sum+dis[j];
			if(x<sum){
				steps++;	
				break;
			}
		}
		i=j;
	}
	return steps+1;
}
int main(){
	while(~scanf("%d %d %d",&L,&n,&m)){
		int maxdis=0;
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		sort(a+1,a+n+1);
		a[0]=0;a[n+1]=L;
		for(int i=1;i<=n+1;i++){
			dis[i]=a[i]-a[i-1];
			maxdis=max(dis[i],maxdis);
		}

	
		
		if(m==1){
			printf("%d\n",L);
			continue;
		}
		else if(m==n+1){
			printf("%d\n",maxdis);
			continue;
		}
		n=n+1;
	
		int left=maxdis,right=L;
		while(left<right){
	
			int mid=(left+right)/2;	
//			system("pause");
//			cout<<mid<<" "<<jump(mid)<<endl;
			if(jump(mid)<=m){
				right=mid;
			}
			else {
				left=mid+1;
			}
		}
		printf("%d\n",left);
	}
}





实战案例四:Claude Code + Excel 技能处理表格数据 Excel 是商业世界中最通用的数据工具。无论是财务报表、销售数据还是项目计划,Excel 无处不在。本案例将展示如何利用 Claude Code 的 Excel 技能,自动化处理复杂的表格数据,告别繁琐的手工操作。 阅读详情

相关推荐

Klocwork安装

简单介绍一下Klocwork在windows下的安装,操作系统是win7,Klocwork的版本是10.0。 第一步:由于Klocwork的安装程序已十分成熟,所以在安装之前不需要什么准备共走。双击Klocwork的安装包,会出现下图的安装引导界面,点击Next按钮。 第二步:下图是协议界面,点击Next按钮。 第三步:选择Klocwork的安装目录,点击Next按钮 第四步:

旮旯 9931

HDU 4004 The Frog's Games (二分 + 贪心 青蛙跳石头)

题意:河长L,n个石头,青蛙最多跳m次,给出n个石头在数轴上的位置,求出青蛙通过石头可以跳过河的最小跳跃能力(跳跃距离)。 思路:二分石头间的距离。 #include #include #include #include #include #include #include using namespace std; typedef long long ll; int str[50

深海沧澜的博客 1147

AppStore逆向分析:从网络抓包到自动化模拟的完整实践

在移动应用生态中,理解客户端与服务器之间的通信协议是进行自动化测试、数据分析和系统集成的关键技术基础。通过分析网络请求与响应,可以深入理解认证、会话管理和数据交换的原理,这对于构建稳定的自动化流程至关重要。其技术价值在于能够实现合法场景下的流程模拟,例如应用元数据监控、沙盒环境测试或内部工具开发。在实际应用场景中,开发者常需处理登录态维持、请求签名验证及风控策略应对等挑战。本文聚焦于AppStore这一封闭生态,详细拆解了其登录、查询等核心环节的通信机制,并探讨了使用Python结合抓包工具进行安全逆向分析

weixin_42524171的博客 929

HDU 4004The Frog's Games(二分)

Description The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to

菜鸟的自我修养 404

NVIDIA 2025 Board Design Engineer 校招笔试

电路分析,矩形波阶跃反馈驱动​,误差信号。非常简单,数电or​离散基础。第一题是考试规矩知情确认。大二暑假做的,纯体验​。五六题太长,下篇分享。

m0_74253823的博客 1130

CTS实战:如何用set_sense优化时钟树平衡(附ICC2避坑指南)

本文深入探讨了在时钟树综合(CTS)中,如何正确使用`set_sense`命令优化时钟树平衡,并对比了其与`set_disable_timing`的本质区别。通过实战案例详细解析了`-stop_propagation`和`-clock_leaf`参数的应用场景,并提供了ICC2工具中的关键避坑指南,帮助后端工程师精准控制时钟拓扑,避免时序分析漏洞。

weixin_28933797的博客 459

hdu 4004题解

-hdu- 4004 题目大意:在宽度为L的河上给定n个落脚点,位置分别给出,通过最多m次跳跃来过河,问我们其中跳跃距离最远的那个值是多少。     题目解析:设ans是相邻落脚点之间的最大距离,所以结果值的范围是【ans, L】。利用二分法缩小这个范围。mid = (left+right)/2;跳跃能力是mid值,如果跳跃次数solve(mid)     代码如下:   #in

u011504498的专栏 755

数字IC后端设计实现之Innovus POD V2 Flow性能优化全解析

本文深入解析了数字IC后端设计中的Innovus POD V2 Flow性能优化方案。该流程通过整合place_opt_design与clock_opt_design命令,实现了布局与时钟树的协同优化,有效提升了时序收敛效率、改善了设计密度与拥塞,并显著减少了迭代次数,是应对先进工艺复杂设计的关键利器。

ik6789012的博客 1254

hdu 4004 (二分+贪心)

题意:青蛙通过河中央的n块石头过河, 所有石头均在与河岸垂直的一条线上,给定每块石头到河岸的距离,给出河的宽L,给定青蛙跳的次数上限m(即青蛙必须经过m或小于m次跳动,过到河对岸),求出青蛙能够过河的最小步长。 当步长为河宽时,青蛙必能跳过,二分步长,求最小步长。 #incl

2422

基于DO-178C/331的飞控软件研发环境的研究

本研究提出了一套基于DO-178C/331标准的飞控系统软件开发和验证框架。通过优化模型库的设计、代码生成配置和测试验证流程,显著提升了飞控系统软件的开发效率和安全性。未来的研究可以进一步扩展模型库的功能,以适应更复杂的飞控系统需求。

qq_41854911的博客 561

实战指南:理解 ThreadLocal 原理并用于Java 多线程上下文管理

探讨如何基于实现一个高效的上下文管理组件,以解决多线程环境下的数据共享和上下文管理这些问题。通过具体的代码示例和实战展示如何为多线程编程提供一种简洁而高效的上下文管理方案。

曾经“等你生日那天”都遥远得像未来,如今却可欢愉的挥手说“下个十年见” 11万+

HDU -4004(二分+贪心)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 The Frog's Games Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 11126Accepted Submis...

WELCOME!!! 380

【k8s故障处理篇】calico-kube-controllers状态为“ImagePullBackOff”解决办法

【k8s故障处理篇】calico-kube-controllers状态为“ImagePullBackOff”解决办法

jks212454的博客 2308

hdu 4004 The Frog's Games 【二分】

The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 4565    Accepted Submission(s): 2225 Problem Description The annua

Fighting! 1717

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

HDU 4004 The Frog's Games 二分 贪心

戳这里:HDU 4004 //思路:二分经典入门题...贪心判方案是否可行 1 #include "bits/stdc++.h" 2 using namespace std; 3 int L, n, m; 4 int pos[500010], dis[500010]; 5 6 bool Cant(int Dis_Jump) 7 { 8 in...

diufeng0879的博客 189

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

HDU 4004 The Frog's Games(二分)

http://acm.hdu.edu.cn/showproblem.php?pid=4004 The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 3072    Accepted

fcbruce 1183

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

The Frog's Games HDU - 4004 二分

The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over th...

mayuqing98的博客 308

HDU 4004 The Frog's Games 【二分】

Problem Description The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the fro...

dianxuanzhi1019的博客 124

【HDU 4004 The Frog's Games】+ 二分

The Frog’s Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 7219 Accepted Submission(s): 3461Problem Description The annual Games in

楚江枫 706

HDU Problem 4004 The Frog's Games 【二分】

The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 6176    Accepted Submission(s): 3010 Problem Description The annual

博客已搬迁到http://www.cnblogs.com/cniwoq/ 332

HDU 4004 The Frog's Games [二分]

二分法找答案#include <cstdio> #include <iostream> #include <algorithm> using namespace std; const int MAXN = 500000 + 9; int l, n, m; int a[MAXN]; bool ok(int x) { //cout << x << endl; int s = 0; //开始跳的点

more time 363

hdu 4004 The Frog's Games 二分+贪心

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 题意:一条长L,(1 思路:二分跳跃的最小距离,然后贪心判断是否能跳过。 #include #include using namespace std; int a[550000],n,m,L; int ok(int k) { int num=1,last0=a[0]

弱菜zc 571

HDU4004The Frog's Games二分!二分!

题目在此 题目大意:一只青蛙被一条宽度为L的河挡住了去路,垂直河岸有一些石头露出水面,这些石头在一条直线上。现在青蛙想要借助这些石头过河,但是最多跳m次,问青蛙最小弹跳多远。 题目分析:要求青蛙的最小弹跳距离,因为青蛙不能落水,所以他至少要跳相邻2块石头以及靠岸的石头与岸边的距离的最小值,青蛙最大弹跳为L。青蛙的弹跳范围有了,于是我们可以选择二分答案。每次估算一个距离,再检查一下,这个距离是否

ophunter的专栏 939

[二分答案]HDU4004 The Frog's Games

也不知道怎么回事,这几天遇到好几道二分答案的题,百度之星也有一道二分水题,于是趁此机会再搞了一下二分。 之前写二分都很纠结,不知道二分结束后指向的值是比目标大一个还是小一个,总之特判特判,搞的代码臭长。。 在数列里面二分都用STL的二分函数搞,然后二分答案的就手写,是r-1还是l+1似乎很有讲究啊,可惜我还没研究透彻。 这题没啥可以说的,就一个二分答案的水题,不过注意R范围,还有记得排序,总

穹妹的家 724

The Frog's Games HDU - 4004(二分)

The annual Games in frogs’ kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over th...

starlet_kiss的博客 248

The Frog's Games HDU - 4004 (二分)

The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over th

白黑菜的博客 365
上一篇: HDU 4006 The kth great number(优先队列)
下一篇: GCD exGCD 逆元 快速幂 大数取模
mirror58229
博客等级 码龄10年 22粉丝 135原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值