题目链接: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. c# dataset 索引0没有值

    datatable绑定到dataGrieView,在刷新datatable的数据时,常会bug:索引0没有值或索引(int)x没有值 昨天弄了一个下午,发现bug原因: dataGridView中有数 ...

  2. 取消双向绑定、输出html代码

    1.取消双向绑定,在绑定的值前加*号. 如: <div id="app"> <p>{{*message}}</p> </div> 2 ...

  3. C# Async与Await用法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. JS中cookie的基本使用

    cookie是本身是HTML中ducument中的一个属性,可以用来保存一些简单的数据信息,比如用户名.密码等,提高一些网站的用户体验度.下面就来简单的说说cookie,它有下面几个特性: 1.有过期 ...

  5. sql server备份还原数据时的问题记录

    1.关于“因为数据库正在使用,所以无法获得对数据库的独占访问权”的最终解决方案 关键SQL语句: ALTER DATABASE [datebase] SET OFFLINE WITH ROLLBACK ...

  6. Delphi 泛型对象类

    { 很早就写了. 只针对delphixe 以上的版本可用. 希望不是自己在造轮子. } 1 unit U_ClassUtility; interface uses generics.defaults, ...

  7. Git - Tutorial [Lars Vogel]

    From: http://www.vogella.com/tutorials/Git/article.html Git - Tutorial Lars Vogel Version 5.6 Copyri ...

  8. ubuntu12.04和deepin12.06使用root账户登录

    修改lightdm.conf登录方式, 1.首先,激活root账户, 在终端中执行 sudo passwd root 连续两次输入 密码,即使root账户的密码,注意密码并不在终端中显示   2. 切 ...

  9. 配置DB2的数据库ODBC连接

    打开cmd窗口,输入db2cmd启动db2 clp窗口 输入db2 list node directory查看是否有数据库需要连接的节点 如果不存在,则 节点编目:db2 catalog tcpip ...

  10. [原创]PostgreSQL Plus Advanced Server批量创建分区表写入亿级别数据实例

    当前情况:大表的数据量已接近2亿条我的解决思路:为它创建n*100个分区表,将各个分区表放在不同的tablespace上这样做的优点:1.首先是对这个级别的数据表的性能会有所提升2.数据管理更科学3. ...