题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=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 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). 
 
题意:一条长L的河中有n块石头,青蛙在原位置通过最多跳m次(每次必须落在石头上或岸上)来通过这条河,求青蛙最远弹跳能力的最小值。
解法:一般看到要求最大值最小什么的,会马上联想到二分搜索。此题就可以用二分来搞。
     二分青蛙最远弹跳能力的值,通过判断最多跳m次是否能够过河来判断此解是否有效,然后求最小即可。
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=+;
int an[maxn];
int L,n,m;
int isok(int len)
{
int step=;
int from=;
int i=;
while (from<L && i<=n+)
{
int j=i;
while (an[i]-from<=len && i<=n+) {j=i ;i++ ; }
step ++ ;
from=an[j];
i=j;
if (step>m) return ;
}
return ;
}
int main()
{
while (scanf("%d%d%d",&L,&n,&m)!=EOF)
{
for (int i= ;i<=n ;i++) scanf("%d",&an[i]);
an[n+]=L;
sort(an+,an+n++);
int l=,r=inf;
int ans=;
while (l<=r)
{
int mid=(l+r)>>;
if (isok(mid)) {ans=mid ;r=mid- ; }
else l=mid+ ;
}
printf("%d\n",ans);
}
return ;
}

hdu 4004 The Frog's Games的更多相关文章

  1. HDU 4004 The Frog's Games(二分答案)

    The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  2. 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) ...

  3. HDU 4004 The Frog's Games(二分)

    题目链接 题意理解的有些问题. #include <iostream> #include<cstdio> #include<cstring> #include< ...

  4. HDU 4004 The Frog's Games(2011年大连网络赛 D 二分+贪心)

    其实这个题呢,大白书上面有经典解法  题意是青蛙要跳过长为L的河,河上有n块石头,青蛙最多只能跳m次且只能跳到石头或者对面.问你青蛙可以跳的最远距离的最小值是多大 典型的最大值最小化问题,解法就是贪心 ...

  5. 杭电 4004 The Frog's Games 青蛙跳水 (二分法,贪心)

    Description The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog T ...

  6. The Frog's Games(二分)

    The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  7. HDUOJ----4004The Frog's Games(二分+简单贪心)

    The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  8. HDU 4004 二分

    The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  9. The Frog's Games

    The Frog's Games Problem Description The annual Games in frogs' kingdom started again. The most famo ...

随机推荐

  1. 用序列化工具写入xml

    标本: <?xml version="1.0" encoding="UTF-8" standalone="true"?> //文 ...

  2. DOS下无法调出中文输入法-Solved

    From:http://www.cnblogs.com/killerlegend/p/3750542.html Author:KillerLegend Date:2014.5.24 DOS下无法打开中 ...

  3. Delphi XE5 for android 使用 BITMAP STYLE DESIGNER 改变控件背景

    一.BITMAP STYLE DESIGNER 工具集成在IDE开发工具的TOOLS菜单. 使用NEW 新建一个安卓样式.NEW—NEW ANDROID STYLE FOR FIREMONKEY. 这 ...

  4. [转]SQLServer 2008以上误操作数据库恢复方法——日志尾部备份

    原文出处:http://blog.csdn.net/dba_huangzj/article/details/8491327 问题: 经常看到有人误删数据,或者误操作,特别是update和delete的 ...

  5. linux C 管道

    单一进程使用管道基本上毫无意义.管道一般用来子进程和父进程之间的通信,或者兄弟进程间的通信. 创建管道的主要函数是pipe #include<unistd.h> ]) pipe函数创建一个 ...

  6. Oracle Imp and Exp (导入和导出) 数据 工具使用

    Oracle 提供两个工具imp.exe 和exp.exe分别用于导入和导出数据.这两个工具位于Oracle_home/bin目录下. 导入数据exp 1 将数据库ATSTestDB完全导出,用户名s ...

  7. Linux编译内核提示'make menuconfig' requires the ncurses libraries错误

    原来使用的ubuntu 11.10系统由于误操作,导致系统崩溃,重新安装了ubuntu 11.10: 在编译内核的时候,提示如下错误: dingq@wd-u1110:~/hwsvn/2sw/1prj_ ...

  8. Drawable

    今天简单的介绍一下有关以下5中的应用: Statelistdrawable Layerdrawable Shapeddrawable Clipdrawable Animationdrawable 1. ...

  9. struts2传递参数值的3中方式

    在使用struts2的时候,当要传递的参数不多的时候,我们会选择使用属性来传参,而当要传递的参数很多的时候,或者多个action会有共用的参数时,我们会使用另外两种传参方式. 注意:使用Model D ...

  10. android开发系列之socket编程

    上周在项目遇到一个接口需求就是通讯系列必须是socket,所以在这篇博客里面我想谈谈自己在socket编程的时候遇到的一些问题. 其实在android里面实现一个socket通讯是非常简单的,我们只需 ...