The Frog's Games

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

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
 
Recommend
lcy
题解:简单二分:
代码:
#include<stdio.h>
#include<queue>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<set>
#include<vector>
using namespace std;
const int MAXN = ;
int L, n, m;
int ston[MAXN];
bool js(int x){
int cnt = , last = ston[];
for(int i = ; i <= n; i++){
if(ston[i] - ston[i - ] > x)
return false;
if(ston[i] - last > x){
cnt++;
last = ston[i - ];
if(cnt >= m)
return false;
}
}
return true;
}
int erfen(int l, int r){
int mid, ans;
while(l <= r){
mid = (l + r) >> ;
if(js(mid)){
ans = mid;
r = mid - ;
}
else
l = mid + ;
}
return ans;
}
int main(){
while(~scanf("%d%d%d", &L, &n, &m)){
for(int i = ; i <= n; i++)
scanf("%d", ston + i);
ston[] = ;
ston[n + ] = L;
n++;
sort(ston, ston + n + );
printf("%d\n", erfen(, L));
}
return ;
}

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. D - The Frog's Games (二分)

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

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

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

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

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

  6. The Frog's Games

    The Frog's Games Problem Description The annual Games in frogs' kingdom started again. The most famo ...

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

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

  8. hdu 4004 The Frog's Games

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

  9. H - The Frog's Games

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

随机推荐

  1. 【leetcode】Merge Sorted Array(合并两个有序数组到其中一个数组中)

    题目: Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assum ...

  2. JMeter基础概念

    JMeter 介绍:一个非常优秀的开源的性能测试工具. 优点:你用着用着就会发现它的重多优点,当然不足点也会呈现出来. 从性能工具的原理划分: Jmeter工具和其他性能工具在原理上完全一致,工具包含 ...

  3. [转载]aptitude与apt-get的区别和联系

    转自 http://www.cnblogs.com/yuxc/archive/2012/08/02/2620003.html 命令 下面将要介绍的所有命令都需要sudo!使用时请将“packagena ...

  4. Gstreamer 中的playback插件

    1. PLAYBACK插件基本介绍 在早期的版本中同时存在playbin和playbin2,但是在最新的版本中,playbin2已经稳定,取代了playbin, playbin不再进行维护.下面是官网 ...

  5. <.net>委托初探

    最近在学<.net深入体验与实战精要>. 今天就来初步讲解下委托. 一句话:委托定义了方法类型,可以将方法当做另一个方法的参数进行传递.委托包涵的只是方法的地址,而不是数据.类似于c指针. ...

  6. ASP.NET中在线用户统计

    统计在线用户的作用不言而喻,就是为了网站管理者可以知道当前用户的多少,然后根据用户数量来观察服务器或者程序的性能,从而可以直观的了解到网站的吸引力或者网站程序的效率.现在,我们就介绍一个简单明了的方法 ...

  7. js判断浏览器类型以及版本

    你知道世界上有多少种浏览器吗?除了我们熟知的IE, Firefox, Opera, Safari四大浏览器之外,世界上还有近百种浏览器. 几天前,浏览器家族有刚诞生了一位小王子,就是Google推出的 ...

  8. Windows服务承载WCF

    Source文件 ------------------------- using System; using System.Collections.Generic; using System.Linq ...

  9. Windows单击右键没有共享选项怎么办

    文件共享是指在网络环境下文件.文件夹.某个硬盘分区使用时的一种设置属性,一般指多个用户可以同时打开或使用同一个文件或数据.但有时候也会遇到找不到共享选项的情况. Windows单击右键没有共享选项怎么 ...

  10. Android studio快捷键Windows版本

    为了方便大家记住这些小技巧和快捷键,我把它写成了一个插件,欢迎大家下载使用:http://chunsheng.me/EasyShortcut/ 快捷键 描述 通用------------------- ...