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) ...
随机推荐
- git看不到别人创建的远程分支
解决办法: $ git fetch //取回所有分支(branch)的更新.如果只想取回特定分支的更新,可以指定分支名,例:$ git fetch <远程主机名> <分支名> ...
- 【C#笔札】Tryparse的用法
这是参考读物的上得一个例子.自己仿照做的作业 private void button1_Click(object sender, EventArgs e) { int P_int_Number,i; ...
- 秒转为时分秒格式js
秒转为时分秒格式 function formatSeconds(value) { if(value == undefined) { value = 0; } var second = parseInt ...
- 第105天:Ajax 客户端与服务器基本知识
一.服务器 前言:通俗的讲,能够提供某种服务的机器(计算机)称为服务器 1.服务器类型 - 按服务类型可分为:文件服务器.数据库服务器.邮件服务器.Web服务器等 - 按操作系统可分为:Linux服务 ...
- telent服务搭建并远程连接
一.Telnet协议 Telnet协议是TCP/IP协议族中的一种,在网络层协议中它属于应用层协议,是Internet远程登陆服务的标准协议.可以使用本地计算机远程连接服务器,从而能够把本地用户所使用 ...
- HDU - 5917 水题
题意:n个点m条边,找点集个数,点集满足有任意三个点成环,或者三个点互不相连 题解:暴力复杂度O(n^5/120*O(ok))==O(能过) //#pragma comment(linker, &qu ...
- Leetcode 50
//1开始我只是按照原来快速幂的思想,当n <0 时,n变成-n,发现当n取-INTMAX时会发生越界的问题,然后在改快速幂代码的时候逐渐了解到快速幂的本质,其实位运算对快速幂来说速度加快不了多 ...
- SGU 139. Help Needed! 逆序数,奇偶性,分析 难度:0
139. Help Needed! time limit per test: 0.25 sec. memory limit per test: 4096 KB Little Johnny likes ...
- java之double类型数值的比较
先看demo: public class L26 { /** * @param args */ public static void main(String[] args) { // TODO Aut ...
- 安卓开发分享功能,分享到facebook网页上不显示图片的问题
最近公司要上分享功能,分享的地方包括微信,qq,facebook,功能完成后,发现分享到facebook的内容只有文字可以显示,图片不显示,其中图片存储是使用七牛的服务器:而分享到微信和qq都可以正常 ...