【题意】

牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离,

现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值。

Sample Input

25 5 2
2
14
11
21
17

Sample Output

4
分析:其实这个和Agressive Cows这道题差不多,只要把起点与终点加入到数组中,然后留下找(N-M+2)个位置之间的最大值,类比与Agressive cows的M;
具体题解可看Agressive cows AC代码:
#include<stdio.h>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int n,m,l;
int a[];
bool cmp (int x,int y)
{
return x<y;
}
bool C(int d)
{
int last=;
for(int i= ; i<(n-m+) ; i++)
{
int crt=last+;
while(crt<n+&&a[crt]-a[last]<d)
crt++;
if(crt==n+)
return false;
last = crt;
}
return true; }
int main()
{
scanf("%d%d%d",&l,&n,&m);
for(int i = ; i <= n ; i++)
scanf("%d",&a[i]);
a[n+]=l;
sort(a,a+n+,cmp);
int en=INF;
int st=; while(en-st>)
{
int mid=(st+en)/;
if(C(mid))
st=mid;
else
en=mid;
}
printf("%d\n",(st+en)/);
return ;
}
												

POJ 3258:River Hopscotch (最大化最小值)的更多相关文章

  1. 二分搜索 POJ 3258 River Hopscotch

    题目传送门 /* 二分:搜索距离,判断时距离小于d的石头拿掉 */ #include <cstdio> #include <algorithm> #include <cs ...

  2. [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6697   Accepted: 2893 D ...

  3. POJ3285 River Hopscotch(最大化最小值之二分查找)

    POJ3285 River Hopscotch 此题是大白P142页(即POJ2456)的一个变形题,典型的最大化最小值问题. C(x)表示要求的最小距离为X时,此时需要删除的石子.二分枚举X,直到找 ...

  4. poj 3258 River Hopscotch 题解

    [题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值 ...

  5. POJ 3258 River Hopscotch

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11031   Accepted: 4737 ...

  6. POJ 3258 River Hopscotch (binarysearch)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5193 Accepted: 2260 Descr ...

  7. POJ 3258 River Hopscotch(二分查找答案)

    一个不错的二分,注释在代码里 #include <stdio.h> #include <cstring> #include <algorithm> #include ...

  8. POJ 3258 River Hopscotch(二分答案)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21939 Accepted: 9081 Desc ...

  9. poj 3258 River Hopscotch(二分搜索之最大化最小值)

    Description Every year the cows hold an ≤ L ≤ ,,,). Along the river between the starting and ending ...

  10. poj 3258"River Hopscotch"(二分搜索+最大化最小值问题)

    传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 块岩石,从中去掉任意 M 块后,求相邻两块岩石最小距离最大是多少? 题解 ...

随机推荐

  1. linux安全关机脚本

    linux安全关机脚本 在断电4分钟后判断关键 目的:在断电以后服务器连接UPS,UPS最多只能支持5分钟也会没电,所以在这里做个判断,如果断电4分钟后,市电还没来就关机. 以下两个设备为两个下路由器 ...

  2. Mac anzhuangxgboost

    2. 从Github库安装XGBoost 第一步, 克隆最新的XGBoost到本地 git clone --recursive https://github.com/dmlc/xgboost 第二步, ...

  3. js 禁止后退键

    function doKey(e) { var ev = e || window.event; //获取event对象 var obj = ev.target || ev.srcElement; // ...

  4. Odometry的发布和发布odom到base_link的tf变换

    转载自http://www.ncnynl.com/archives/201702/1328.html ROS发布nav_msgs/Odometry消息,以及通过tf从“odom”坐标系到“base_l ...

  5. [GO]数组指针做函数参数

    package main import "fmt" //p指向实现数组a,它是指向数组,它是数组指针//*p指向指针指向的内存,就是实参a func modify1(p *[]in ...

  6. C++函数后面加throw关键字简记

    看代码时候看到fun() throw()的用法,找到一篇blog解释很简单,如下: C++函数后面加关键字throw(something)限制,是对这个函数的异常安全性作出限制. 举例及解释如下: v ...

  7. Reading Text-based Files In ASP.NET

    Friday, July 17, 2015 1:43 PM Every time I need to work with the contents of text-based files in an ...

  8. UIView 和 CALayer区别 为啥有UIView还要CALayer?

    今天,被坑了,面试的时候没回答出来,特此记录一下 一.继承结构 1: UIView的继承结构为: UIResponder : NSObject UIResponder是用来响应事件的,也就是UIVie ...

  9. VIVADO生成MCS

    tcl console里面执行 write_cfgmem -format mcs -interface spix4 -size 128 -loadbit "up 0 E:/x.bit&quo ...

  10. jquery.parser.js 的 parseOptions 方法

    // target 是DOM元素 // properties 是宿主的属性 $.parser.parseOptions(target,properties); /** * parse options, ...