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. SQL Server经典函数之数字去零

    需求: 针对带有小数点的数字信息,去除小数点后多余的零 可能存在的情况: 1.精度范围内,出现多余的零    eg:1234.3400     想要的结果为1234.34 2.精度变大出现的多余的零, ...

  2. javase---Java反射操作

    1首先认识什么叫反射 正常的情况下,我们操作一个对象,则必须找到这个对象对应的类,然后实例化,然后再做各种操作, 反射的则通过一个对象获取对应的类,然后实例化,然后做各种操作, 2反射的操作步骤 I获 ...

  3. 南京网络赛I-Skr【回文树模板】

    19.32% 1000ms 256000K A number is skr, if and only if it's unchanged after being reversed. For examp ...

  4. nginx:负载均衡的session共享

    一.场景 当nginx做了负载均衡之后,同一个ip的url请求服务器的时候,负载均衡会根据每台服务器的权重等一些设置将请求转发到不同的服务器上去进行处理,这样的话针对一些带有状态请求的情况来说就是个很 ...

  5. Mongo副本集的配置以及php node.js连接使用副本集

    最近弄了下mongodb的副本集, 首先说下没有认证情况的副本集,相对比较简单,因为环境有限,我在同一台服务器上做了模拟. --rest参数是打开web监控页面,比如我们这里监听37017端口,则打开 ...

  6. 点击劫持漏洞解决( Clickjacking: X-Frame-Options header missing)

    点击劫持漏洞 X-Frame-Options HTTP 响应头, 可以指示浏览器是否应该加载一个 iframe 中的页面. 网站可以通过设置 X-Frame-Options 阻止站点内的页面被其他页面 ...

  7. Java char 和 String 的区别: 字符编码及其存储

    一. ASCII码 上个世纪60年代,美国制定了一套字符编码,对英语字符与二进制位之间的关系,做了统一规定.这被称为ASCII码,一直沿用至今.一个字节(8bit)一共 可以用来表示256种不同的状态 ...

  8. 【Python】Python 读取csv的某行或某列数据

    Python 读取csv的某行 转载 2016年08月30日 21:01:44 标签: python / csv / 数据   站长用Python写了一个可以提取csv任一列的代码,欢迎使用.Gith ...

  9. Mirror--生成用于镜像用户同步的脚本

    USE master GO IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL DROP PROCEDURE sp_hexadecimal GO CREATE PR ...

  10. 002-Spring Framework-Core-01-IoC容器

    一.概述 文章地址:https://docs.spring.io/spring/docs/5.0.6.RELEASE/spring-framework-reference/ 核心主要包括:IoC co ...