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 ...
随机推荐
- (转)Linux bash shell脚本语法入门
http://www.linuxsky.org/doc/newbie/201004/389.html 1.基础 #!/bin/bash //bash脚本第一句都是这个,他会让系统指定以bash来解释这 ...
- apache archiva安装教程
1. 下载archiva standalone http://archiva.apache.org/download.cgi 2. 解压,设置ARCHIVA_HOME 环境变量 3.为了防止冲突, ...
- FilterDispatcher 的作用(struts2.1.3以前,新版本改了)
org.apache.struts2.dispatcher.FilterDispatcher是Struts2的主要的Filter,负责四个方面的功能: (1)执行Actions (2)清除Action ...
- Android全局变量使用
1.通过一个Data.java实例类,能够实现全局数据保存,这里就不多说了,学Java的都知道. 2.Android特有的Application,是应用的入口,执行贯穿整个app执行过程,能够在这个类 ...
- Linux菜鸟学习笔记--Linux系统结构
什么是Linux? Linux是一种自由和开放源码的类Unix操作系统,存在着许多不同的Linux版本,但它们都使用了Linux内核.严格来讲,Linux这个词本身只表示Linux内核,但实际上人 ...
- Tips:javascript 图片放大和取得尺寸
1)获取图片尺寸 <img src="http://img.my.csdn.net/uploads/201309/03/1378223257_7957.jpg" alt=&q ...
- ng-camera的API详解
Camera github地址: apache/cordova-plugin-camera 安装 cordova plugin add cordoba-plugin-camera 项目中的使用
- 小学生之KTV播放原理
第一步: 创建一个Song类 //歌曲名称 public string SongName { get; set; } //歌曲路劲 public string SongPath { get; set ...
- web前端之文件上传
前言 最近太忙一直没时间认真的写博客(哈哈哈),最近pm提一个需求,移动端需要一个上传图片的功能,允许多选.删除.预览.点击查看大图并可以滑动.虽然听起来很多,但是这个功能在web上实现过啊,使用we ...
- linux分区和系统文件和挂载
要以root用户进入 .查看磁盘情况 lsblk .进行分区 sudo cfdisk /dev/sda 在空闲资源的地方新建分区,然后一步步的走下来就行了,最后选择write,然后quit 重启 .创 ...