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) ...
随机推荐
- 一些常用的JavaScript正则表达式
1.正数,最多n位小数 /^(([1-9]\d*(\.\d{1,n})?)|(0\.\d{1,n}))$/ 2.手机号码 /^1[34578]\d{9}$/
- CGI, FCGI, SCGI, WSGI 释异
IKI Links: CGI - http://en.wikipedia.org/wiki/Common_Gateway_Interface FCGI - http://en.wikipedia.or ...
- CMS收集器和G1收集器
CMS收集器 CMS收集器是一种以获取最短回收停顿时间为目标的收集器.基于"标记-清除"算法实现,它的运作过程如下: 初始标记 并发标记 重新标记 并发清除 初始标记.从新标记这两 ...
- [java]java String.split()函数的用法分析
转自:http://swiftlet.net/archives/709 一.在java.lang包中有String.split()方法的原型是: public String[] split(Strin ...
- Android Studio 中实现高德定位并获取相应信息
Android开发项目时常常会遇到定位这个功能,所以写了这篇博客,今天主要讲的高德地图的定位并获取相应信息. 首先导入高德的jar包 选中jar包右键点击 Add As Library, 在buil ...
- Java研发工程师知识点总结
Java研发工程师知识点总结 最近一次更新2017年12月08日 大纲 一.Java基础(语言.集合框架.OOP.设计模式等) 二.Java高级(JavaEE.框架.服务器.工具等) 三.多线程和并发 ...
- CSS border 属性和 border-collapse 属性
border 简写属性在一个声明设置所有的边框属性. 可以按顺序设置如下属性: border-width border-style border-color 如果不设置其中的某个值,也不会出问题,比如 ...
- 99. Recover Binary Search Tree -- 找到二叉排序树中交换过位置的两个节点
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...
- IOS-网络(GET请求和POST请求、HTTP通信过程、请求超时、URL转码)
// // ViewController.m // IOS_0129_HTTP请求 // // Created by ma c on 16/1/29. // Copyright © 2016年 博文科 ...
- 简话Angular 00 为什么要学Angular
一句话: 现在不学Angular的结局,就和5年前不学JQuery一样! 谁学谁知道,早学早进阶! 1. JQuery vs Javascipt 问两个问题: 1) 你用过JQuery吗?当然! 2) ...