HDU 4004
http://acm.hdu.edu.cn/showproblem.php?pid=4004
题意:青蛙过长L的河,只能落在石头上,石头数量是n,给出n个坐标,至多跳m次,求在可以过河的条件下,青蛙跳的最大距离的最小值
水题,二分答案即可,验证的时候青蛙显然应尽可能落在远端
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stack>
#include <set> using namespace std; int L,n,m;
int a[]; int OK(int x){
int now=;
if(x>=L)return ;
if(n>= && x>=a[n-]){
if(x>=L-a[n-] && m>=)return ;
return ;
}
int cnt=;
for(int i=;i<n-;i++){
if(now+x>=a[i] && now+x<a[i+]){
now=a[i];
cnt++;
}
}
if(now+x>=L){
cnt++;
if(cnt<=m)return ;
return ;
}
if(now+x>=a[n-]){
cnt++;
now=a[n-];
if(now+x>=L){
cnt++;
if(cnt<=m)return ;
return ;
}
else return ;
}
return ;
} int main(){
while(~scanf("%d%d%d",&L,&n,&m)){
for(int i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int l,r;
l=;r=;
while(r-l>=){
int mid=(l+r)>>;
if(OK(mid))r=mid;
else l=mid;
}
for(int i=l;i<=r;i++){
if(OK(i)){
printf("%d\n",i);
break;
}
}
}
return ;
}
HDU 4004的更多相关文章
- hdu 4004 The Frog's Games
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 The annual Games in frogs' kingdom started again ...
- hdu 4004 (二分加贪心) 青蛙过河
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4004 题目意思是青蛙要过河,现在给你河的宽度,河中石头的个数(青蛙要从石头上跳过河,这些石头都是在垂 ...
- hdu 4004 最大值最小化
http://acm.hdu.edu.cn/showproblem.php?pid=4004 一条线段长度为L,线段上有n个点,最多选取 m-1 个点,使得包括线段端点在内的相邻点之间的最大距离值最小 ...
- HDU 4004 The Frog's Games(二分)
题目链接 题意理解的有些问题. #include <iostream> #include<cstdio> #include<cstring> #include< ...
- hdu 4004 二分 2011大连赛区网络赛D
题意:一个长为L的河,中间有n个石子,小青蛙需要跳少于m次过河,判断小青蛙每次跳跃最大距离的最小值 最大值最小,用二分 Sample Input 6 1 2 2 25 3 3 11 2 18 Samp ...
- HDU 4004 The Frog's Games(二分答案)
The Frog's Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- HDU 4004 二分
The Frog's Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- HDU 4004 The Frog's Games(二分+小思维+用到了lower_bound)
The Frog's Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- HDU 4004 The Frog's Games(2011年大连网络赛 D 二分+贪心)
其实这个题呢,大白书上面有经典解法 题意是青蛙要跳过长为L的河,河上有n块石头,青蛙最多只能跳m次且只能跳到石头或者对面.问你青蛙可以跳的最远距离的最小值是多大 典型的最大值最小化问题,解法就是贪心 ...
随机推荐
- Java 集合系列 02 Collection架构
java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...
- java中将一个字符数组赋值给另一个,两者同时变化
java中将一个字符数组赋值给另一个,两者的变化怎么是同步的?怎么才能让他们独立开? 比如有一个int[][] a 已经存在值,现在定义int[][] b=a;之后改变a的值,为何b也跟着改变?怎么才 ...
- spring使用jackson返回object报错:Handler execution resulted in exception: Could not find acceptable representation
问题:在springmvc中添加Jackson jar包返回Object类型,处理器方法的produces属性不写,默认根据类型,但如果指定了(错误原因)produces = "text/h ...
- 冲销交货单WS_REVERSE_GOODS_ISSUE
LOOP AT ITAB. AT END OF VBELN. PERFORM FRM_LOCK_DELIVERY(ZSDS0002) USING ITAB-VBELN. CALL FUNCTION ' ...
- 函数调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。
在dllimport中加入CallingConvention参数就行了,[DllImport(PCAP_DLL, CharSet = CharSet.Auto, CallingConvention = ...
- Stylus Studio的安装与卸载
- centos 运用ssh的rsa算法实现无密码登录
ssh 公钥和私钥原理 1.客户端机子生成私钥和公钥,将公钥放到服务器证书中,然后就可以实现免密码登录.(服务器认证文件要有该登录用户的读执行权限) 2.a登录b: a机子:test01账号(b也要建 ...
- Java 多线程中run() 与 start() 的不同
区别:调用start方法实现多线程,而调用run方法没有实现多线程 Start: 用start方法来启动线程,真正实现了多线程运行,这时无需等待run方法体代码执行完毕而直接继续执行下面的代码.通过调 ...
- Android的SwipeToDismiss第三方开源框架模拟QQ对话列表侧滑删除,置顶,将头像图片圆形化处理。
<Android SwipeToDismiss:左右滑动删除ListView条目Item> Android的SwipeToDismiss是github上一个第三方开源框架(github ...
- P264练习题1.2题
package 集合; import java.util.*; public class fourteen { public static void main(String[] args) { //1 ...