HDU 4004 二分
The Frog's Games
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 7307 Accepted Submission(s): 3492
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).
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.
2
25 3 3
11
2
18
11
using namespace std;
int a[500005]={0},L,M,maxn,N;
int solve(int k)
{
if(maxn>k) return 0;
int s=1,x=0,i,j;
for(i=1;i<=N;++i)
if(a[i]-a[x]<=k&&a[i+1]-a[x]>k) {x=i;s++;}
return s<=M;
}
int main()
{
int i,j,k;
while(cin>>L>>N>>M){maxn=0;
for(i=1;i<=N;++i) {
scanf("%d",&a[i]);
}a[N+1]=L;
sort(a+1,a+1+N); //由于输入时的无序所以要排序
for(i=1;i<=N+1;++i) maxn=max(maxn,a[i]-a[i-1]); //第一次在输入时做的这一步导致整个的失败哎,以后要注意!
int l=0,r=L,mid;
while(l<r){
mid=l+(r-l)/2;
if(solve(mid)){
r=mid;
}
else{
l=mid+1;
}
}
cout<<l<<endl;
}
return 0;
}
HDU 4004 二分的更多相关文章
- hdu 4004 (二分加贪心) 青蛙过河
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4004 题目意思是青蛙要过河,现在给你河的宽度,河中石头的个数(青蛙要从石头上跳过河,这些石头都是在垂 ...
- hdu 4004 二分 2011大连赛区网络赛D
题意:一个长为L的河,中间有n个石子,小青蛙需要跳少于m次过河,判断小青蛙每次跳跃最大距离的最小值 最大值最小,用二分 Sample Input 6 1 2 2 25 3 3 11 2 18 Samp ...
- hdu 4024 二分
转自:http://www.cnblogs.com/kuangbin/archive/2012/08/23/2653003.html 一种是直接根据公式计算的,另外一种是二分算出来的.两种方法速度 ...
- 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(二分+小思维+用到了lower_bound)
The Frog's Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- HDU 4004 The Frog's Games(2011年大连网络赛 D 二分+贪心)
其实这个题呢,大白书上面有经典解法 题意是青蛙要跳过长为L的河,河上有n块石头,青蛙最多只能跳m次且只能跳到石头或者对面.问你青蛙可以跳的最远距离的最小值是多大 典型的最大值最小化问题,解法就是贪心 ...
- HDU 4004 The Frog's Games(二分)
题目链接 题意理解的有些问题. #include <iostream> #include<cstdio> #include<cstring> #include< ...
- HDU 4004
http://acm.hdu.edu.cn/showproblem.php?pid=4004 题意:青蛙过长L的河,只能落在石头上,石头数量是n,给出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 ...
随机推荐
- opencv学习笔记——cv::line函数详解
void cvLine( CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1, int line_type=8, ...
- Mybatis解决sql中like通配符模糊匹配 构造方法覆盖 mybits 增删改
<select id="getRecByNameWildcard" parameterType="Student" resultMap="res ...
- 每次收到的 HTTP 请求,就可以打开一个 SqlSession,返回一个响应,就关闭它
mybatis – MyBatis 3 | 入门 http://www.mybatis.org/mybatis-3/zh/getting-started.html 作用域(Scope)和生命周期 理解 ...
- flask的session用法2
from flask import Flask, session, redirect, url_for, escape, request app = Flask(__name__) @app.rout ...
- 过山车---hdu2063(最大匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063最大匹配模板题: #include <iostream> #include <c ...
- 比特币BTC全节点搭建
比特币BTC全节点搭建 #环境 ubuntu 16.4 #硬盘500GB #截止2018-12-31磁盘占用超过230GB #客户端安装 #下载页面 #https://bitcoin.org/zh_C ...
- vsftpd文件服务器安装与配置
-d<登入目录>:指定用户登入时的启始目录:. -s<shell>:指定用户登入后所使用的shell: /sbin/nologin指的是不允许login当前Linux系统.当用 ...
- mysql 表的增删改查
一.表介绍 表相当于文件,表中的一条记录就相当于文件的一行内容,不同的是,表中的一条记录有对应的标题,称为表的字段 对于一张表来说,字段是必须要有的. 数据表 类似于excel id,name,qq, ...
- android gson使用
第一步注册: compile 'com.google.code.gson:gson:2.6.2' 第二步初始化: Gson gson = new GsonBuilder() .setLenient( ...
- 1059. C语言竞赛(20)
原题: https://www.patest.cn/contests/pat-b-practise/1059 思路: 参赛者id是数组下标, 数组值是参赛者排名位置(从1开始), 每次判断0不存在, ...