The Frog's Games

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 9678    Accepted Submission(s): 4428

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


InputThe 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.OutputFor 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
题意:蛤蟆直线过河,直线上有石头可以踩,告诉你河的宽度还有石头个数还有最多可以跳几次,每种过河方案都有一个单次跳的最大距离,让你求出所有方案里面单次跳的距离最小的那个方案,并输出这个距离
从单次跳的最大距离下手进行二分,而过河最少跳一次,所以单次跳的最大距离应该就是河的跨度
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
int a[];
int main()
{
int l,n,m;
while(~scanf("%d %d %d",&l,&n,&m))
{
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
a[++n]=l;//把河的长度也放进去
sort(a+,a++n);//排序
int ri=l,mid;
int le=l/m;
if(le*m<l)//为了保证以le的长度跳m次(不管石头的情况下)一定能到对岸
le++;
int mm=l;
while(le<=ri)
{
mid=(le+ri)/;
int sum=;
for(int i=;i<=m;i++)//以mid的距离模拟跳m次看看能不能到
{
int y=sum+mid;//直接跳能到达的距离
int p=lower_bound(a+,a++n,y)-a;//p是这次最远能跳的石头编号+1
if(a[p]!=y&&(p==||a[p]==sum))//要是p是当前的石头,代表这次不能跳到任何的石头上,失败
break;
if(a[p]!=y)//因为是lower_bound(大于等于),所以如果不是y处有石头的话,要减一
p--;
sum=a[p];
}
if(sum!=l)
le=mid+;
else if(sum==l)
{
if(mm>mid)//挑出最小的
mm=mid;
ri=mid-;
}
}
printf("%d\n",mm);
}
return ;
}
 

HDU 4004 The Frog's Games(二分+小思维+用到了lower_bound)的更多相关文章

  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(二分)

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

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

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

  4. hdu 4004 The Frog's Games

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 The annual Games in frogs' kingdom started again ...

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

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

  6. D - The Frog's Games (二分)

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

  7. The Frog's Games(二分)

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

  8. hdu 4004 (二分加贪心) 青蛙过河

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4004 题目意思是青蛙要过河,现在给你河的宽度,河中石头的个数(青蛙要从石头上跳过河,这些石头都是在垂 ...

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

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

随机推荐

  1. Codeforces Round #402 (Div. 2) A,B,C,D,E

    A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...

  2. 大白菜的装机U盘真不错

    今天用大白菜制作了个启动U盘,然后在里面,把[电脑公司]的ghost文件拷贝进去. 重新安装WinXP成功. 注意: 1)直接用[电脑公司]的ISO文件,用Win32DiskImage写到U盘,不知为 ...

  3. Java实现时钟小程序【代码】

    哎,好久没上博客园发东西了,上一次还是两个月前的五一写的一篇计算器博客,不过意外的是那个程序成了这学期的Java大作业,所以后来稍微改了一下那个程序就交了上去,这还是美滋滋.然后五月中旬的时候写了一个 ...

  4. (GoRails)ActiveRecord --explain方法:(优化你的查询)

    https://gorails.com/episodes/activerecord-explain?autoplay=1 比如没有加index的查询和加了index的查询,调用数据库的速度就差5倍. ...

  5. LINUX QQ

    查询龙井QQ http://www.longene.org/forum/viewtopic.php?f=6&t=4700

  6. C#接口作用

    1.C#接口的作用 : C#接口是一个让很多初学C#者容易迷糊的东西,用起来好像很简单,定义接口,里面包含方法,但没有方法具体实现的代码,然后在继承该接口的类里面要实现接口的所有方法的代码,但没有真正 ...

  7. 在laravel视图中直接使用{{ csrf_token() }}被翻译成英文显示的处理方法

    在表单中加一个input框在放入{{ csrf_token() }}就可以了: 方法如下: <input type="hidden" name="_token&qu ...

  8. bzoj1025

    题意: 找环 有多少种不同的排列 使排列数目为n 题解: 考虑dp f[i][j]表示前i个质数,和为j的方案数 然后转移一下即可 代码: #include<bits/stdc++.h> ...

  9. C# #if, #else和#endif预处理指令

        #if 使您可以开始条件指令,测试一个或多个符号以查看它们是否计算为 true.如果它们的计算结果确实为true,则编译器将计算位于 #if 与最近的 #endif 指令之间的所有代码.例如, ...

  10. HDU4607 Park Visit

    肯定会想到树的直径: 如果直径够长,就在直径(1+8)上面找路径,ans=k. 如果不够长,肯定会在有点分叉点(如3,4,5)回溯,然后我们把路径拉直,把其中一条的作为主线(有机化学,ORZ),主线是 ...