poj 3258 River Hopscotch(二分搜索之最大化最小值)
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 ( ≤ L ≤ ,,,). Along the river between the starting and ending rocks, N ( ≤ N ≤ ,) more rocks appear, each at an integral distance Di from the start ( < 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 ( ≤ 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 : Three space-separated integers: L, N, and M
Lines ..N+: 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 : A single integer that is the maximum of the shortest distance a cow has to jump after removing M rocks
Sample Input
Sample Output
Hint
Before removing any rocks, the shortest jump was a jump of from (the start) to . After removing the rocks at and , the shortest required jump is a jump of (from to or from to ).
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
#define N 50006
int dis[N];
int L,n,m;
bool solve(int min_dis){
int last=;
int cnt=;
for(int i=;i<=n+;i++){
if(dis[i]-dis[last]<=min_dis) cnt++;
else last=i;
} if(cnt>m) return true;
return false; }
int main()
{ while(scanf("%d%d%d",&L,&n,&m)==){
for(int i=;i<=n;i++){
scanf("%d",&dis[i]);
} if(n==m){
printf("%d\n",L);
continue;
} dis[]=;
dis[n+]=L;
sort(dis+,dis+n+);
int low=;
int high=L;
while(low<high){
int mid=(low+high)>>;
if(solve(mid)){
high=mid;
}
else{
low=mid+;
}
}
printf("%d\n",low);
}
return ;
}
poj 3258 River Hopscotch(二分搜索之最大化最小值)的更多相关文章
- [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6697 Accepted: 2893 D ...
- poj 3258"River Hopscotch"(二分搜索+最大化最小值问题)
传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 块岩石,从中去掉任意 M 块后,求相邻两块岩石最小距离最大是多少? 题解 ...
- 二分搜索 POJ 3258 River Hopscotch
题目传送门 /* 二分:搜索距离,判断时距离小于d的石头拿掉 */ #include <cstdio> #include <algorithm> #include <cs ...
- River Hopscotch(二分最大化最小值)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9923 Accepted: 4252 D ...
- POJ 3258 River Hopscotch(二分查找答案)
一个不错的二分,注释在代码里 #include <stdio.h> #include <cstring> #include <algorithm> #include ...
- poj 3258 River Hopscotch 题解
[题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值 ...
- POJ 3258 River Hopscotch
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11031 Accepted: 4737 ...
- POJ 3258 River Hopscotch (binarysearch)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5193 Accepted: 2260 Descr ...
- POJ 3258 River Hopscotch(二分答案)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21939 Accepted: 9081 Desc ...
随机推荐
- protobuf2.5 iphone5s中崩溃的问题
我们的游戏用到了protobuf2.5,在其他版本中都是好的,但iphone5s中崩溃,表现为针对DescriptorPool为空了.网上也找不到什么信息,xiaozhong同学各种尝试,都没有搞定, ...
- 程序员实用的 MySQL sql 语句
这儿只讲究实用, 程序员编程时常用到的 MySQL的 sql语句(不包括基本的 select, update, delete 等语句). 1. 添加一个用户build,并赋予所有权限的命令 gran ...
- linux 常用find命令
1.查找当前目录下以test开头的所有文件-会进入子目录中去查找 [root@rusky hgfs]# find -name test* 2.查找当前目录下名为test.txt的文件-会进入子目录中去 ...
- 【转】 LINQ To SQL 语法及实例大全
LINQ to SQL语句(1)之Where Where操作 适用场景:实现过滤,查询等功能. 说明:与SQL命令中的Where作用相似,都是起到范围限定也就是过滤作用的,而判断条件就是它后面所接的子 ...
- SQL Server 2005无日志文件附加数据库
公司网站运营两年多了,日志文件超级大,在重装系统的时候,为了省事,就没有备份日志文件,而且是没有分离就把日志文件给删掉了(下次一定要记得先分离再删日志文件).结果造成数据库怎么都附加不上.出现错误. ...
- Errore HTTP 404.2 - Not Found" IIS 7.5 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理
解决方法: 找到IIS的根节点->右侧“ISAPI和CGI限制”->把禁止的ASP.Net版本项设置为允许. 如下图 今天配置本地iis出现了一些问题,第一个是出现cgi等错误,iis重新 ...
- 使用.NET框架、Web service实现Android的文件上传(二)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYUAAAKpCAIAAADcx6fPAAAgAElEQVR4nOydd1hT5+LHg1attbfr1t ...
- 服务器重启后Oracle监听服务没有自动启动的解决方案
最近一直在被这样一个问题烦恼,就是服务器断电重启后,Oracle监听服务没有正常自动启动(监听服务已经设置为自启动). 具体是这样的,监听服务设置为开机自启动,Oracle数据库服务设置为开机延时启动 ...
- 分享8款精美的jQuery图片播放插件
本文将和大家一起分享8款精美的jQuery图片播放插件,每一款插件均有演示和源码下载,有兴趣的朋友可以下载使用和研究.废话不多说了,直接上这些插件. 1.3D轮播相册 这款3D相册插件利用了HTML5 ...
- 近期Responsive web design项目经验分享-高分辨率图片处理篇
在高分辨率的情况下 商品的图片难免会失真 怎样才能让商品的图片在高分辨率的情况下 效果不失真 提供用户更好的体验呢 我发现了一个解决方案 不知道是不是你想要的 先上图片对比下效果 左侧是使用后 ...