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 ...
 
随机推荐
- SQL---->mySQl数据库1------表内容的增删改查
			
增: insert into user(id,username,birthday,entry_date,job,salary,resume) values(1,'aaaa','1995-12-10', ...
 - B. Factory Repairs---cf627B(线段树)
			
题目链接:http://codeforces.com/problemset/problem/627/B 题意:有一个工厂生产零件,但是机器是不正常的,需要维修,维修时间是 k 天,在维修期间不能生产, ...
 - Team Formation---zoj3870(异或)
			
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5518 题意就是有n个数,如果满足a^b > MAX(a, b) ...
 - docker网络部分源码分析
			
daemon初始化network controller daemon的配置,网络部分的内容在cmd/dockerd/config_common_unix.go中指定,默认设置一般都为空 // daem ...
 - Spark提交应用程序之Spark-Submit分析
			
1.提交应用程序 在提交应用程序的时候,用到 spark-submit 脚本.我们来看下这个脚本: if [ -z "${SPARK_HOME}" ]; then export S ...
 - HDU4135Co-prime(容斥原理)
			
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4135 题目解析: 给你一个闭区间[A,B](1 <= A <= B <= 1015) ...
 - 一个很大的文件,存放了10G个整数的乱序数列,如何用程序找出中位数。
			
一.梳理审题 一.看清题目: 注意这个题目的量词,这个文件中有10G个整数,而不是这个文件占了10G的内存空间. 二.一些疑问: 在计算机中我们讲的G.M等都是存储容量的概念,但是一般都会在会面加上B ...
 - 120. Triangle(动态规划  三角形最小路径  难 想)
			
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
 - Python中的MySQL接口:PyMySQL & MySQLdb
			
MySQLdb模块只支持MySQL-3.23到5.5之间的版本,只支持Python-2.4到2.7之间的版本 PyMySQL支持 Python3.0以后的版本 PyMySQL https://pypi ...
 - C#——图片操作类简单封装
			
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Dr ...