传送门

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. python SMTP 发送邮件 阿里企业邮箱、163邮箱 及535错误

    class SendEmail(object): def __init__(self, type, to_addr): self.to_addr = to_addr self.sys_date = t ...

  2. iOS的非常全的三方库,插件,大牛博客

    转自: http://www.cnblogs.com/zyjzyj/p/6015625.html github排名:https://github.com/trending, github搜索:http ...

  3. 清北学堂(2019 4 28 ) part 2

    主要内容数据结构: 1.二叉搜索树 一棵二叉树,对于包括根节点在内的节点,所有该节点左儿子比此节点小,所有该节点右儿子比该节点大,(感觉好像二分...) 每个节点包含一个指向父亲的指针,和两个指向儿子 ...

  4. BZOJ 1443 游戏(二分图博弈)

    新知识get. 一类博弈问题,基于以下条件: 1.博弈者人数为两人,双方轮流进行决策.2.博弈状态(对应点)可分为两类(状态空间可分为两个集合),对应二分图两边(X集和Y集).任意合法的决策(对应边) ...

  5. 【GZOI2015】石子游戏 博弈论 SG函数

    题目大意 有\(n\)堆石子,两个人可以轮流取石子.每次可以选择一堆石子,做出下列的其中一点操作: 1.移去整堆石子 2.设石子堆中有\(x\)个石子,取出\(y\)堆石子,其中\(1\leq y&l ...

  6. bzoj 4542: [Hnoi2016]大数 (莫队)

    Description 小 B 有一个很大的数 S,长度达到了 N 位:这个数可以看成是一个串,它可能有前导 0,例如00009312345.小B还有一个素数P.现在,小 B 提出了 M 个询问,每个 ...

  7. IDEA中Maven项目使用Junit4单元测试的写法

    IDEA默认是安装了junit控件的,直接使用就好了 在maven项目的pom.xml文件中添加依赖 <dependency> <groupId>junit</group ...

  8. MT【291】2元非齐次不等式

    实数$x,y$满足$x^2+y^2=20,$求$xy+8x+y$的最大值___ 法一:$xy\le\dfrac{1}{4}x^2+y^2,8x\le x^2+16,y\le\dfrac{1}{4}y^ ...

  9. CodeForces 97 E. Leaders(点双连通分量 + 倍增)

    题意 给你一个有 \(n\) 个点 \(m\) 条边的无向图,有 \(q\) 次询问,每次询问两个点 \(u, v\) 之间是否存在长度为奇数的简单路径. \(1 \le n, m, q \le 10 ...

  10. Hdoj 2602.Bone Collector 题解

    Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone C ...