River Hopscotch(二分最大化最小值)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 9923 | Accepted: 4252 |
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
Output
Sample Input
25 5 2
2
14
11
21
17
Sample Output
4
Hint
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define T_T while(T--)
const int MAXN=50010;
int rock[MAXN];
int N,M;
int js(int x){
int cnt=0;
int last=rock[0];
for(int i=1;i<=N+1;i++){
if(rock[i]-last<x){
cnt++;
}
else last=rock[i];
}
return cnt;
}
int erfen(int l,int r){
int mid;
while(l<=r){
mid=(l+r)>>1;
if(js(mid)>M)r=mid-1;//就把等号去了,后面变成l-1就对了。。。。
else l=mid+1;
}
return l-1;
}
int main(){
int L;
while(~scanf("%d%d%d",&L,&N,&M)){
rock[0]=0;
for(int i=1;i<=N;i++)SI(rock[i]);
rock[N+1]=L;
sort(rock,rock+N+2);
printf("%d\n",erfen(0,L));
}
return 0;
}
River Hopscotch(二分最大化最小值)的更多相关文章
- poj 3258"River Hopscotch"(二分搜索+最大化最小值问题)
传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 块岩石,从中去掉任意 M 块后,求相邻两块岩石最小距离最大是多少? 题解 ...
- POJ_2456_Agressive_cows_(二分,最大化最小值)
描述 http://poj.org/problem?id=2456 有n个小屋,线性排列在不同位置,m头牛,每头牛占据一个小屋,求最近的两头牛之间距离的最大值. Aggressive cows Tim ...
- [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6697 Accepted: 2893 D ...
- POJ 3258:River Hopscotch 二分的好想法
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9326 Accepted: 4016 D ...
- River Hopscotch(二分POJ3258)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9263 Accepted: 3994 Descr ...
- POJ_3258_River_Hopscotch_[NOIP2015]_(二分,最大化最小值)
描述 http://poj.org/problem?id=3258 给出起点和终点之间的距离L,中间有n个石子,给出第i个石子与起点之间的距离d[i],现在要去掉m个石子(不包括起终点),求距离最近的 ...
- POJ 3258 River Hopscotch(二分答案)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21939 Accepted: 9081 Desc ...
- POJ3258 River Hopscotch —— 二分
题目链接:http://poj.org/problem?id=3258 River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total ...
- POJ3258 River Hopscotch(二分最大化最小值)
题目链接:http://poj.org/problem?id=3258 题意:给n个石头,起点和终点也是两个石头,去掉这石头中的m个,使得石头间距的最小值最大. 思路:二分石头间的最短距离,每次贪心地 ...
随机推荐
- 获取文件数据流+叠加byte数组(给byte数组加包头包尾)
OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "(*.mp4)|*.mp4|(*.*)|*.*"; ofd.Res ...
- 浅谈Spring(一)
一.Spring引言 Spring是一款轻量级框架,代码入侵量很小,并且还是众多优秀的设计模式的组合(工厂.代理.模板.策略). 特点: 1.方便解耦,简化开发 通过Spring提供的IoC容器,我们 ...
- JavaSE复习日记 : java包机制
这里是第一个文件,命名为JavaSE_01.java,我在这个文件里面声明了一个m1()方法,通过包机制,我将在另外一个文件夹里访问这个文件里的东西,确切的说是访问这个文件生成的一个class文件; ...
- wampserver 绑定域名(wampserver 本地域名测试配置)
一.tomact 配置虚拟主机 1.打开Apache菜单下“httpd.conf”文件: 找到“# Include conf/extra/httpd-vhosts.conf” , 把这句前面的#号去掉 ...
- 四轴飞行器1.2.2 RT-Thread 串口
四轴飞行器1.2.2 RT-Thread 串口 本来是打算说根据RT-Thread的设备管理提供的驱动接口些串口驱动的,但是仔细一看,我去,串口驱动写好了,只需要调用就可以了.下面我们说 ...
- Less基础教程
Less基础教程 less是较早出现的css预处理器. LESS API 参考 安装和使用 安装比较简单,通过nmp或bower安装即可. npm install less -g bower inst ...
- 转: linux文件链接(软链接和硬链接)
链接:一种在共享文件和访问它的用户的若干目录项之间建立联系的一种方法. Linux中包括两种链接:硬链接(Hard Link)和软链接(Soft Link),软链接又称为符号链接(Symbolic l ...
- protel99与win7兼容问题的解决方案
一些用户大概都已经把自己的 PC 从 winXP 换到了 win7,在 win7 给我们带来的视觉上的冲击和功能上的更换.也不时的带来了各方面的软件兼容问题 ,而一般上的兼容都可以在 win7 的自动 ...
- Jsoup代码解读之四-parser
Jsoup代码解读之四-parser 作为Java世界最好的HTML 解析库,Jsoup的parser实现非常具有代表性.这部分也是Jsoup最复杂的部分,需要一些数据结构.状态机乃至编译器的知识.好 ...
- opencv 简单、常用的图像处理函数(2)
opencv的项目以来配置和环境变量的配置都很简单,对于我这个没有c++基础的来说,复杂的是opencv的api和一些大部分来自国外没有翻译的资料,以及一些常见的编码问题. 资料 opencv 中文a ...