POJ 3258 River Hopscotch (二分)

来源:互联网 发布:淘宝上怎么买枪暗号 编辑:程序博客网 时间:2024/04/28 11:34

Description

Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight river with a rock at the start and another rock at the end, L units away from the start (1 ≤ L ≤ 1,000,000,000). Along the river between the starting and ending rocks, N (0 ≤ N ≤ 50,000) more rocks appear, each at an integral distance Di from the start (0 < Di < L).

To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping only from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river.

Farmer John is proud of his cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rocks placed too closely together. He plans to remove several rocks in order to increase the shortest distance a cow will have to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he has enough resources to remove up to M rocks (0 ≤ M ≤ N).

FJ wants to know exactly how much he can increase the shortest distance before he starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow has to jump after removing the optimal set of M rocks.


Input

Line 1: Three space-separated integers: L, N, and M

Lines 2..N+1: Each line contains a single integer indicating how far some rock is away from the starting rock. No two rocks share the same position.


Output

Line 1: A single integer that is the maximum of the shortest distance a cow has to jump after removing M rocks


Sample Input

25 5 2214112117


Sample Output

4


题意

一条长l的河中,有n个垫脚石,现在给出它们距离起始点的距离,要求移除其中的m块,使得间距最小的两块石头之间的距离最大。


思路

和 POJ 3273 一样的题型,相应的,我们可以利用二分去判断路径中的每一个间距,判断mid区间下需要去掉多少个垫脚石,然后做出调整。


AC 代码

#include <iostream>#include<stdio.h>#include<queue>#include<string.h>#include<algorithm>#include<math.h>using namespace std;int a[51000],n,l,m;int solve(int high,int low){    while(low<=high)    {        int mid=(low+high)/2;   //当前需要判断的间距        int count=0;            //可以去掉的垫脚石数目        int s=0,e=1;        while(e<n)        {            if(a[e]-a[s]>=mid)  //一个包含mid的区间判断完毕                s=e,e++;            else e++,count++;   //继续扩充区间        }        if(count>m)             //区间过大            high=mid-1;        else low=mid+1;    }    return high;}int main(){    while(~scanf("%d%d%d",&l,&n,&m))    {        int high=l,low=(1<<25);        a[0]=0,a[n+1]=l;        n+=2;        for(int i=1; i<n-1; i++)            scanf("%d",a+i);        sort(a,a+n);        for(int i=1; i<n; i++)            low=min(low,a[i]-a[i-1]);        printf("%d\n",solve(high,low));    }}
1 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 衣服上面粘了胶怎么办 衣服上的胶干了怎么办 凌晨4点到火车站怎么办 运管罚款没钱交怎么办 郑州地铁票没买怎么办 遇到吸毒者拦路威胁要钱怎么办 开车遇见拦路要钱的怎么办 高速上有人拦车怎么办 马路上有人拦车怎么办 苹果手机下截软件要钱怎么办 孩子在学校问同学要钱怎么办 在学校被同学要钱怎么办 把人家店砸了要怎么办 外汇出金不到账怎么办 把罚款单弄丢了怎么办 在12306买不到下铺怎么办有 地铁票买反了怎么办 香港买错特惠票怎么办 到达迪拜t3 后怎么办 海藻面膜调多了怎么办 被鸡爪子抓伤了怎么办 被鸡抓伤肿了怎么办 护士电子化没有激活码怎么办 窗帘盒螺丝掉了怎么办 窗帘的环扣掉了怎么办 门式起重吊装行车脱轨怎么办 在日本丢了东西怎么办 在日本钱包丢了怎么办 被起诉后没钱还怎么办 分期付款卖车打不起车款怎么办 地铁票买多了怎么办 工伤陪护费没有发票怎么办 工伤医疗费报销单位不盖章怎么办 家里的led灯坏了怎么办 吊顶led灯坏了怎么办 客厅空了一面墙怎么办 轨道灯的轨道不够长怎么办 奔驰大灯不亮了怎么办 led顶灯不亮了怎么办 吸顶灯led灯坏了怎么办 车底盘塑料被刮怎么办