传送门

https://www.cnblogs.com/violet-acmer/p/9793209.html

题意:

  有 N 块岩石,从中去掉任意 M 块后,求相邻两块岩石最小距离最大是多少?

题解:

  二分答案(假设答案为res)

  定义 l = 0 , r = L ;

  mid = (l+r)/2 ;

  判断当前答案 mid 至少需要去除多少块岩石,如果去除的岩石个数 > M,说明当前答案mid > res,r=mid;反之,说明当前答案 mid <= res , l =mid;

AC代码:

 #include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=5e4+; int L,N,M;
int dist[maxn]; bool Check(int mid)
{
int res=;
int pre=;
for(int i=;i <= N;++i)
{
if(dist[i]-dist[pre] < mid)
res++;
else
pre=i;
}
return res <= M ? true:false;
}
int Solve()
{
sort(dist+,dist+N+);
int l=,r=L+;
while(r-l > )
{
int mid=l+((r-l)>>);
if(Check(mid))
l=mid;
else
r=mid;
}
return l;
}
int main()
{
scanf("%d%d%d",&L,&N,&M);
dist[]=;
for(int i=;i <= N;++i)
scanf("%d",dist+i);
printf("%d\n",Solve());
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. POJ 3258 River Hopscotch(二分查找答案)

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

  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(二分答案)

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

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

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

  9. POJ 3258 River Hopscotch(二分法搜索)

    Description Every year the cows hold an event featuring a peculiar version of hopscotch that involve ...

随机推荐

  1. AI算法第三天【矩阵分析与应用】

  2. APP测试重点(转载)

      1.安装卸载测试: app在不同的操作系统(安卓和ios),不同的版本,不同的机型上是否都能安装成功: 在安装过程中,突然断网或网络不好,是否给出有好的提示,网络恢复之后是否能正常下载: 在安装过 ...

  3. Simple Use IEnumerable<T>

    Private static IEnumerable<T> FunDemo(T para) { while(...) { .... yield return Obj; } } static ...

  4. U68641 划水(swim.pas/c/cpp)

    U68641 划水(swim.pas/c/cpp) 题目背景 小小迪带你划水. 题目描述 原题 输入输出格式 输入格式: 第一行一个数 T. 接下来 T 行每行一个数表示 n 输出格式: 输出 T 行 ...

  5. 百年老图难倒谷歌AI,兔还是鸭?这是个问题

    上面这张图,画的是鸭子还是兔子? 自从1892年首次出现在一本德国杂志上之后,这张图就一直持续引发争议.有些人只能看到一只兔子,有些人只能看到一只鸭子,有些人两个都能看出来. 心理学家用这张图证明了一 ...

  6. 未能写入输出文件“c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2da42acc\ab2935

    未能写入输出文件“c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2da42acc\ab293 ...

  7. kubernetes Helm基本操作

    创建: helm install --name demo --set Persistence.Enabled=false stable/jenkins 查看: kubectl get po,svc - ...

  8. P2141 珠心算测验

    P2141 题目描述 珠心算是一种通过在脑中模拟算盘变化来完成快速运算的一种计算技术.珠心算训练,既能够开发智力,又能够为日常生活带来很多便利,因而在很多学校得到普及. 某学校的珠心算老师采用一种快速 ...

  9. Crazy Circuits HDU - 3157(有源汇有上下界最小流)

    给出每条边的下界 求最小流 板题 提供两个板子代码 虽然这个题 第一个比较快 但在loj上https://loj.ac/problem/117 的板题  第一个1700+ms 第二个才600+ms   ...

  10. django-pure-pagination 组件使用

    django-pure-pagination 组件 用于在 django 中自动创建分页 官方详见 github : 这里 安装 pip install django-pure-pagination ...