The Frog's Games

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

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
 
Source
 久违的惨案,错误tm竟然是因为没排序就去找最大差值只能怪自己傻逼了,很水的一个二分调到结束=  =
#include<bits/stdc++.h>
using namespace std;
int a[500005]={0},L,M,maxn,N;
int solve(int k)
{
   if(maxn>k) return 0;
   int s=1,x=0,i,j;
   for(i=1;i<=N;++i)
       if(a[i]-a[x]<=k&&a[i+1]-a[x]>k) {x=i;s++;}
   return s<=M;
}
int main()
{

int i,j,k;
    while(cin>>L>>N>>M){maxn=0;
        for(i=1;i<=N;++i) {
                scanf("%d",&a[i]);
        }a[N+1]=L;
        sort(a+1,a+1+N);   //由于输入时的无序所以要排序
        for(i=1;i<=N+1;++i) maxn=max(maxn,a[i]-a[i-1]);   //第一次在输入时做的这一步导致整个的失败哎,以后要注意!
        int l=0,r=L,mid;
        while(l<r){
            mid=l+(r-l)/2;
            if(solve(mid)){
              r=mid;
            }
            else{
              l=mid+1;
            }
        }
        cout<<l<<endl;
    }
    return 0;

}

HDU 4004 二分的更多相关文章

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

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

  2. hdu 4004 二分 2011大连赛区网络赛D

    题意:一个长为L的河,中间有n个石子,小青蛙需要跳少于m次过河,判断小青蛙每次跳跃最大距离的最小值 最大值最小,用二分 Sample Input 6 1 2 2 25 3 3 11 2 18 Samp ...

  3. hdu 4024 二分

    转自:http://www.cnblogs.com/kuangbin/archive/2012/08/23/2653003.html   一种是直接根据公式计算的,另外一种是二分算出来的.两种方法速度 ...

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

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

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

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

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

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

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

  8. HDU 4004

    http://acm.hdu.edu.cn/showproblem.php?pid=4004 题意:青蛙过长L的河,只能落在石头上,石头数量是n,给出n个坐标,至多跳m次,求在可以过河的条件下,青蛙跳 ...

  9. hdu 4004 The Frog's Games

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

随机推荐

  1. Google Now 'not available in your country'

    Google Now 'not available in your country' Don't know how to cope with this problem.

  2. SDL结合QWidget的简单使用说明

    SDL(Simple DirectMeida Layer)是一个简单的封装媒体库,功能主要涉及了相关于OpenGL或者DirectX的显卡硬件功能和一些鼠标,键盘等外设访问.这里主要只说明一下它的渲染 ...

  3. 记一次踩坑:使用ksoap-android时造成的okhttp依赖冲突问题

    项目中需要调用webservice接口,android SDK中并没有直接访问webservice接口的方法,于是我引入了ksoap-android的jar包,来实现访问webservice接口.刚开 ...

  4. angular自定义指令命名的那个坑

    Directive 先从定义一个简单的指令开始. 定义一个指令本质上是在HTML中通过元素.属性.类或注释来添加功能.AngularJS的内置指令都是以ng开头,如果想自定义指令,建议自定义一个前缀代 ...

  5. 很靠谱linux常用命令

    vim是打开vim编辑器,别的编辑器还有vi(功能没有vim 强大),nano,emacs等等,感觉还是vim最强大,其次是vi,别的就要差一些了. 我听我们老师说,用图形界面本身已经会被高手笑了,如 ...

  6. 005-线程sleep、join、yield、wait、notify、notifyAll、run、start、synchronized

    一.线程sleep join yield wait 1.sleep() 使当前线程(即调用该方法的线程)暂停执行一段时间,让其他线程有机会继续执行,但它并不释放对象锁.也就是说如果有synchroni ...

  7. git-【六】分支的创建与合并

    在版本回填退里,已经知道,每次提交,Git都把它们串成一条时间线,这条时间线就是一个分支.截止到目前,只有一条时间线,在Git里,这个分支叫主分支,即master分支.HEAD严格来说不是指向提交,而 ...

  8. Spark Shuffle(三)Executor是如何fetch shuffle的数据文件(转载)

    1. 前言 在前面的博客中讨论了Executor, Driver之间如何汇报Executor生成的Shuffle的数据文件,以及Executor获取到Shuffle的数据文件的分布,那么Executo ...

  9. Kafka丢失数据问题优化总结

    数据丢失是一件非常严重的事情事,针对数据丢失的问题我们需要有明确的思路来确定问题所在,针对这段时间的总结,我个人面对kafka 数据丢失问题的解决思路如下: 是否真正的存在数据丢失问题,比如有很多时候 ...

  10. 1124 Raffle for Weibo Followers[简单]

    1124 Raffle for Weibo Followers(20 分) John got a full mark on PAT. He was so happy that he decided t ...