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. 在outlook中查找Skype的聊天记录

    在outlook中和inbox平级,有一个Conversation History

  2. POJ 2443 Set Operation(压位加速)

    http://poj.org/problem?id=2443 题意: 有1000个集合,每个集合有至多10000个数,之后输入多个询问,判断询问的两个数是否位于同一个集合. 思路: 位运算...很强大 ...

  3. package 'yaml-cpp' not found

    -- Using these message generators: gencpp;genlisp;genpy -- checking for module 'yaml-cpp' -- package ...

  4. a href 属性

    两种用法: 页面跳转时使用 url (部分浏览器会阻止新窗口弹出页面),其他情况一律遵循          ‘结构样式行为分离’ 1. url href="#"     文档顶部  ...

  5. Linux删除(清空)正在运行的应用日志文件内容 及 查看服务器剩余空间

    在测试环境定位问题时,如果发现日志文件内容太多或太大,有时需要删除该日志,如Tomcat,Nginx日志.以前每次都是先rm -rf ***.log,然后重启应用.直到后来发现了以下命令,原来可以不用 ...

  6. Apereo CAS - 1

    1. download  cas 4.2.2 from https://github.com/apereo/cas/releases 2. eclipse import cas 4.2.2 eclip ...

  7. mysql中InnoDB存储引擎的行锁和表锁

    Mysql的InnoDB存储引擎支持事务,默认是行锁.因为这个特性,所以数据库支持高并发,但是如果InnoDB更新数据的时候不是行锁,而是表锁的话,那么其并发性会大打折扣,而且也可能导致你的程序出错. ...

  8. ps怎么替换颜色

    1.图像--->>调整--->>替换颜色

  9. APP的六种loading加载样式,全在这...

    今天这篇文章是给大家分享的loading加载的设计,文章里面会有一些实例在这分享给大家! 大多数App都要与服务器进行数据的交换,App向服务器发出数据请求,服务器接收到请求之后向App传输相应数据, ...

  10. 054——VUE中vue-router之实例讲解定义一下单页面路由

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...