题意:一个长为L的河,中间有n个石子,小青蛙需要跳少于m次过河,判断小青蛙每次跳跃最大距离的最小值

最大值最小,用二分

Sample Input
6 1 2
2
25 3 3
11
2
18
Sample Output
4
11
 
2015-07-27:备战区域赛专题
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt,L;
int a[MAXN];
int check(int m)
{
int tot=;
int k=; //目前待的石头
int w=;
while(tot<L)
{
int o=k+;
if(a[o]-a[k]>m)
{
return ;
}
while(m>=a[o]-a[k])
{
o++;
}
k=o-;
tot+=a[o]-a[k];
w++;
}
return w;
}
int main()
{
int i,j,k;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
while(~scanf("%d%d%d",&L,&n,&m))
{
for(i=;i<=n;i++) scanf("%d",&a[i]);
a[]=;
a[n+]=L;
sort(a,a+n+);
a[n+]=;
int l=,r=L;
int ans=;
while(l<=r)
{
int mid=(r+l)>>;
if(check(mid)&&check(mid)<=m)
{
ans=mid;
r=mid-;
}
else l=mid+;
}
printf("%d\n",ans);
}
}
 
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=;
int n,m,t,L;
int d[maxn];
bool fun(int x) //判断青蛙跳x的时候需要跳几次过河,贪心,每次选择能跳最远的
{
int now=,tot=;
int cnt=;
while(now<L)
{
now+=x;
while(now>=d[tot]) tot++;
now=d[tot-];
cnt++;
}
if(cnt<=m) return true;
else return false;
}
int main()
{
int i,j,k;
//freopen("1.in","r",stdin);
while(scanf("%d%d%d",&L,&n,&m)!=EOF)
{
for(i=;i<=n;i++) scanf("%d",&d[i]);
sort(d+,d+n+);
d[]=;
d[n+]=L;
d[n+]=; //用来判断跳几次过河的边界
int l=,r=L,mid;
int ans; //记录最小值
for(i=;i<=n+;i++) l=l<d[i]-d[i-]?d[i]-d[i-]:l; //求出两个相邻石子之间的最大距离,也就是青蛙要跳的最小距离
while(l<=r)
{
mid=(l+r)>>;
if(fun(mid)) ans=mid,r=mid-;
else l=mid+;
}
printf("%d\n",ans);
}
}

hdu 4004 二分 2011大连赛区网络赛D的更多相关文章

  1. hdu 4006 优先队列 2011大连赛区网络赛F **

    签到题都要想一会 #include<cstdio> #include<iostream> #include<algorithm> #include<cstri ...

  2. hdu 4001 dp 2011大连赛区网络赛A

    题意:给一些指定长宽高的砖,求能累出的最大高度,不同砖有不同编号,每种编号对下面的砖做出了限制 dp 注意输出要用%I64d,否则会wa,以后不用%lld了 Sample Input 3 10 10 ...

  3. hdu 4005 双联通 2011大连赛区网络赛E *****

    题意: 有一幅图,现在要加一条边,加边之后要你删除一条边,使图不连通,费用为边的费用,要你求的是删除的边的最小值的最大值(每次都可以删除一条边,选最小的删除,这些最小中的最大就为答案) 首先要进行缩点 ...

  4. hdu 4003 树形dp+分组背包 2011大连赛区网络赛C

    题意:求K个机器人从同一点出发,遍历所有点所需的最小花费 链接:点我 Sample Input 3 1 1 //3个点,从1出发,1个机器人 1 2 1 1 3 1 3 1 2 1 2 1 1 3 1 ...

  5. hdu 4002 欧拉函数 2011大连赛区网络赛B

    题意:求1-n内最大的x/phi(x) 通式:φ(x)=x*(1-1/p1)*(1-1/p2)*(1-1/p3)*(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是 ...

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

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

  7. HDU 5875 Function -2016 ICPC 大连赛区网络赛

    题目链接 网络赛的水实在太深,这场居然没出线zzz,差了一点点,看到这道题的的时候就剩半个小时了.上面是官方的题意题解,打完了才知道暴力就可以过,暴力我们当时是想出来了的,如果稍稍再优化一下估计就过了 ...

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

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

  9. hdu 4035 2011成都赛区网络赛E 概率dp ****

    太吊了,反正我不会 /* HDU 4035 dp求期望的题. 题意: 有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结点i都有3种可能: 1.被杀死,回到结点 ...

随机推荐

  1. C# 汉字转拼音

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Comm ...

  2. C# ManualResetEvent 的方法介绍

        名称 说明 1. Close 在派生类中被重写时,释放由当前 WaitHandle 持有的所有资源. (继承自 WaitHandle.)在XNA Framework中,此成员由 Close() ...

  3. EF图解

  4. hdu.5203.Rikka with wood sticks(数学推导:一条长度为L的线段经分割后可以构成几种三角形)

    Rikka with wood sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  5. Constructing Roads (MST)

    Constructing Roads Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  6. CloudPlatform和CloudStack的关系

    The Scalr team is at the CloudStack Collab Conf, and this post summarizes a few things we learned. C ...

  7. js实现鼠标右键自定义菜单(弹出层),并与树形菜单(TreeView)、iframe合用(兼容IE、Firefox、Chrome)

    <table class="oa-el-panel-tree"> <tr> <td style="vertical-align: top; ...

  8. 专注docker安全:Security Scanning

    导读 Docker毫无疑问是近期运维同学们的热点话题,Docker安全也由此倍受重视,Docker Security Scanning 是一款Docker镜像扫描的安全工具,目前已经在Docker C ...

  9. 转:PCL+VS2010环境配置

    1.下载 http://www.pointclouds.org/downloads/windows.html出下载PCL完全安装包1.6.0 all-in-one-installer,我的电脑是32位 ...

  10. python-twisted

    环境:win7 64位,python 2.7.3 安装: http://twistedmatrix.com/Releases/Twisted/14.0/Twisted-14.0.0.win-amd64 ...