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)
Total Submission(s): 9678 Accepted Submission(s): 4428
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)的更多相关文章
- HDU 4004 The Frog's Games(二分答案)
The Frog's Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- HDU 4004 The Frog's Games(二分)
题目链接 题意理解的有些问题. #include <iostream> #include<cstdio> #include<cstring> #include< ...
- HDU 4004 The Frog's Games(2011年大连网络赛 D 二分+贪心)
其实这个题呢,大白书上面有经典解法 题意是青蛙要跳过长为L的河,河上有n块石头,青蛙最多只能跳m次且只能跳到石头或者对面.问你青蛙可以跳的最远距离的最小值是多大 典型的最大值最小化问题,解法就是贪心 ...
- hdu 4004 The Frog's Games
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 The annual Games in frogs' kingdom started again ...
- 杭电 4004 The Frog's Games 青蛙跳水 (二分法,贪心)
Description The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog T ...
- D - The Frog's Games (二分)
The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. On ...
- The Frog's Games(二分)
The Frog's Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- hdu 4004 (二分加贪心) 青蛙过河
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4004 题目意思是青蛙要过河,现在给你河的宽度,河中石头的个数(青蛙要从石头上跳过河,这些石头都是在垂 ...
- HDUOJ----4004The Frog's Games(二分+简单贪心)
The Frog's Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
随机推荐
- 【同步时间】Linux设置时间同步
所有节点都要确保已安装ntpd(在步骤4已安装) 1.首先选择一台服务器作为时间服务器. 假设选定为node1.sunny.cn服务器为时间服务器. 2.ntp服务器的配置 修改ntp.conf文件: ...
- Tinkoff Challenge - Elimination Round D. Presents in Bankopolis(区间DP)
http://codeforces.com/contest/793/problem/D 题意:给出一些点和他们之间的距离,是有向的,这些点从1~n顺序排列,现在选出k个点组成一条路径,使他们之间的距离 ...
- CSS 再学习,基础篇
语法 h1 {color:red; font-size:14px;} 共享声明 h1,h2,h3,h4,h5,h6 { color: green; } 继承 通过 CSS 继承,子元素将继承最高级元素 ...
- m_Orchestrate learning system---二十八、字體圖標iconfont到底是什麼
m_Orchestrate learning system---二十八.字體圖標iconfont到底是什麼 一.总结 一句话总结: 阿里巴巴 图标库 iconfont-阿里巴巴矢量图标库 1.表格的t ...
- 递归--练习2--noi6261汉诺塔
递归--练习2--noi6261汉诺塔 一.心得 先把递推公式写出来,会很简单的 二.题目 6261:汉诺塔问题 总时间限制: 1000ms 内存限制: 65536kB 描述 约19世纪末,在欧州 ...
- Java实现GUI计算器【代码】
这几天用java写了一个计算器程序,开始写的时候原本只是想实现一下GUI(这个是直接读三个字母还是什么“固椅”的发音)界面,熟悉一下Java GUI 编程,为Java期末大作业练练手,本以为代码不会很 ...
- zoj3261变形并查集
需要变形的并查集,这题错了好久,一直没a掉,终于在重写第三次的时候a了 先保存数据,把不需要拆分的边合并,逆向计算,需要拆分时就合并,之前不知道为啥写搓了,tle好久 #include<map& ...
- openv+contrib配置总结
本文转载于:https://www.cnblogs.com/wjy-lulu/p/6805557.html 开门见山的说:别用opencv3.0,这个版本添加扩展库不怎么好,能不能成功我不敢说,我是试 ...
- Page.TryUpdateModel 方法
使用来自值提供程序的值更新指定的模型实例. 使用来自值提供程序的值更新指定的模型实例. 命名空间: System.Web.UI程序集: System.Web(System.Web.dll 中) ...
- app手机端连接tomcat电脑端服务器
1.你要在电脑端开启并启动tomcat 2.启动nginx,然后需要在nginx中配置好端口号,每一个app的模块端口号是不一样的,需要你进行更改 3.如下图代表app连接的端口: 4.关于sql过滤 ...