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. Spring - Bean Definition Bean定义 给容易提供元数据的3方法

    Spring Bean Definition https://www.tutorialspoint.com/spring/spring_bean_definition.htm The objects ...

  2. ERROR 2002 (HY000): Can't connect to local MySQL server through socket

    原文链接:https://blog.csdn.net/u011262253/article/details/82802157 一.错误现场还原: 下面我们通过三种方式来连接,然后观察提示的错误信息: ...

  3. 内核通信之Netlink源码分析-用户内核通信原理3

    2017-07-06 上节主讲了用户层通过netlink和内核交互的详细过程,本节分析下用户层接收数据的过程…… 有了之前基础知识的介绍,用户层接收数据只涉及到一个核心调用readmsg(), 其他的 ...

  4. (2.3)DDL增强功能-流程化控制与动态sql

    1.流程控制 在T-SQL中,与流程控制语句相关的关键字有8个: BEGIN...END BREAK GOTO CONTINUE IF...ELSE WHILE RETURN WAITFOR 其实还可 ...

  5. EasyUI Resizable 可调整尺寸

    通过 $.fn.resizable.defaults 重写默认的 defaults. 用法 通过标记创建可调整尺寸(resizable)对象. <div class="easyui-r ...

  6. html基础之css标签

    css style: 里面的写的就叫做css,每一个样式的间隔用英文分号, 全部相同的时候引用class. css有三种写法: 1.在head标签中增加style标签,在style标签中去写css样式 ...

  7. POJ1175:Starry Night(bfs)

    http://poj.org/problem?id=1175 题目解析: 这个题因为数据的原因可以很水的过,但我因为把1e-8写成了1e-9WA了N遍,一直WA,题目意思很简单就是相似图形(就是求旋转 ...

  8. (转)Terraform,自动化配置与编排必备利器

    本文来自作者 QingCloud实践课堂 在 GitChat 上分享 「Terraform,自动化配置与编排必备利器」 Terraform - Infrastructure as Code 什么是 T ...

  9. mysql性能测试-tpcc

    mysql性能测试-tpcc Tpcc-mysql TPC-C是专门针对联机交易处理系统(OLTP系统)的规范 Tpcc-mysql由percona根据规范实现 TPCC流程  更能模拟线上业务   ...

  10. Educational Codeforces Round 57 Solution

    A. Find Divisible 签到. #include <bits/stdc++.h> using namespace std; int t, l, r; int main() { ...