其实这个题呢,大白书上面有经典解法 
  题意是青蛙要跳过长为L的河,河上有n块石头,青蛙最多只能跳m次且只能跳到石头或者对面。问你青蛙可以跳的最远距离的最小值是多大

  典型的最大值最小化问题,解法就是贪心二分。其实就是二分答案,再把每次二分出来的答案带入计算是否满足题意,以此来确定这个正确答案在此值的左区间还是右区间。可以这么做的依据是:对于二分出来的值x满足条件的话,则大于x(或者小于x)也满足条件,这样就得到一个单调的规律,满足二分。

#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define eps 1E-8
/*注意可能会有输出-0.000*/
#define Sgn(x) (x<-eps? -1 :x<eps? 0:1)//x为两个浮点数差的比较,注意返回整型
#define Cvs(x) (x > 0.0 ? x+eps : x-eps)//浮点数转化
#define zero(x) (((x)>0?(x):-(x))<eps)//判断是否等于0
#define mul(a,b) (a<<b)
#define dir(a,b) (a>>b)
typedef long long ll;
typedef unsigned long long ull;
const int Inf=<<;
const double Pi=acos(-1.0);
const int Max=;
int sto[Max],dis[Max];
int Solve(int n,int ll)//判断情况
{
int ans=,sum=;
for(int i=;i<n;i++)
{
if(sum+dis[i]>ll)
{
ans++;
sum=dis[i];
}
else
sum+=dis[i];
}
ans++;
return ans;
}
int Dic(int l,int n,int m,int manx)//二分
{
int sma=manx,big=l;
while(sma<big)
{
int mid=((big+sma)>>);
if(Solve(n,mid)<=m)
big=mid;
else
sma=mid+;
}
return big;
}
int main()
{
int l,n,m;
while(~scanf("%d %d %d",&l,&n,&m))
{
sto[]=;
for(int i=; i<=n; i++)
scanf("%d",&sto[i]);
n++;
sto[n++]=l;
sort(sto,sto+n);
int nn=;
for(int i=; i<n; i++)
if(sto[i]!=sto[nn])
sto[++nn]=sto[i];
n=++nn;
int manx=;
for(int i=; i<n-; i++)
{
dis[i]=sto[i+]-sto[i];
manx=max(manx,dis[i]);
}
n--;
printf("%d\n",Dic(l,n,m,manx));
}
return ;
}

HDU 4004 The Frog's Games(2011年大连网络赛 D 二分+贪心)的更多相关文章

  1. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  2. HDU 4004 The Frog's Games(二分答案)

    The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  3. 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) ...

  4. hdu 4004 The Frog's Games

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 The annual Games in frogs' kingdom started again ...

  5. HDU 4004 The Frog's Games(二分)

    题目链接 题意理解的有些问题. #include <iostream> #include<cstdio> #include<cstring> #include< ...

  6. hdu 4033 2011成都赛区网络赛 余弦定理+二分 **

    二分边长,判断最后内角和是否为2pi,注意l与r的选取,保证能组成三角形 #include<cstdio> #include<iostream> #include<alg ...

  7. HDU 4001 To Miss Our Children Time(2011年大连网络赛 A 贪心+dp)

    开始还觉得是贪心呢... 给你三类积木叫你叠楼房,给你的每个积木包括四个值:长 宽(可以互换) 高 类型d d=0:你只能把它放在地上或者放在 长 宽 小于等于 自己的积木上面 d=1:你只能把它放在 ...

  8. HDU 5884 Sort(2016年青岛网络赛 G 二分+贪心+小优化)

    好题 题意:给你n<=100000个数,每个数范围[0,1000],然后给你一个最大的代价T,每次最多合并k个数成为一个数,代价为k个数的总和.问最后合成1个数的总代价不大于T的最小k 题解:我 ...

  9. HDU 5869 Different GCD Subarray Query(2016大连网络赛 B 树状数组+技巧)

    还是想不到,真的觉得难,思路太巧妙 题意:给你一串数和一些区间,对于每个区间求出区间内每段连续值的不同gcd个数(该区间任一点可做起点,此点及之后的点都可做终点) 首先我们可以知道每次添加一个值时gc ...

随机推荐

  1. jmeter操作myql数据库

    1.先安装mysql的驱动mysql-connector-java-5.1.7-bin.jar 配置jdbc的connection configuration Database Url :jdbc:m ...

  2. 部署网站时的错误“one of its dependencies.试图加载格式不正确的程序。”解决方案。

    Sever Error in '/' Application.Could not load file or assembly 'SresBase' or one of its dependencies ...

  3. Youth Is Not a Time of Life

    Youth is not a time of life; it is a state of mind.青春不是年华,而是心境: It is not a matter of rosy cheeks, r ...

  4. 【BZOJ1811】[Ioi2005]mea 乱搞

    [BZOJ1811][Ioi2005]mea Description 考虑一个非递减的整数序列 S1,....Sn+1(Si<=Si+1 1<=i<=n). 序列M1...Mn是定义 ...

  5. LIS(模板)

    记录一下,O(nlgn)的算法求LIS //HHH #include <iostream> #include <stdio.h> #include <string.h&g ...

  6. (七)solr7之Terms组件的使用

    (七)solr7之Terms组件的使用 Terms组件提供访问索引项的字段和每个词相匹配的文档数量. 这可以用于建立一个自动建议特性或任何其他的特性,而这个terms不是搜索或文档级别的水平.快速检索 ...

  7. window子对象

    Window 子对象 (1)Location 对象 Location 对象包含有关当前 URL(统一资源定位符) 的信息.(Uniform Resource Location) Location 对象 ...

  8. Nginx服务监听端口修改启动bug

    监听的端口从80 修改到其他端口出现启动不起来问题. 解决方案如下: yum install policycoreutils-python sudo cat /var/log/audit/audit. ...

  9. jQuery中删除节点方法remove()、detach()、empty()分析

    jQuery中提供了三种删除节点的方法:remove().detach().empty(),本文详细分析这三种方法. 最容易区分的是empty(),该方法严格上属于“清空节点”,即删除其子节点,自身并 ...

  10. Oracle学习笔记—归档模式

    什么是归档模式 Oracle数据库有联机重做日志,这个日志是记录对数据库所做的修改,比如插入,删除,更新数据等,对这些操作都会记录在联机重做日志里.一般数据库至少要有2个联机重做日志组.当一个联机重做 ...