传送门

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. java sort排序原理

    事实上Collections.sort方法底层就是调用的Arrays.sort方法,而Arrays.sort使用了两种排序方法,快速排序和优化的归并排序. 快速排序主要是对那些基本类型数据(int,s ...

  2. Spring Boot 构建电商基础秒杀项目 (四) getotp 页面

    SpringBoot构建电商基础秒杀项目 学习笔记 BaseController 添加 public static final String CONTENT_TYPE_FORMED = "a ...

  3. 13.kubernetes之pv,pvc,configmap(带补充实例)

    管理存储是管理计算的一个明显问题.该PersistentVolume子系统为用户和管理员提供了一个API,用于抽象如何根据消费方式提供存储的详细信息.为此,我们引入了两个新的API资源:Persist ...

  4. cuda编程-矩阵乘法(2)

    采用shared memory加速 代码 #include <stdio.h> #include <stdlib.h> #include <math.h> #inc ...

  5. Using MongoDB with Web API and ASP.NET Core

    MongoDB is a NoSQL document-oriented database that allows you to define JSON based documents which a ...

  6. ACM之路——上车了

    校赛坚持到底,拿到了银牌:第一批进入ACM队集训,期末考试之前仍然代码不断,甚至感觉对不起大学第一次的期末考试,五天复习高数,两天复习英语,看到英语成绩是胸口突然好痛,好难受……就为了成为ACM正式队 ...

  7. codeforces611C

    New Year and Domino CodeForces - 611C 他们说:“每一年都像多米诺骨牌,一个接一个地倒下去”.但是,一年能够像多米诺骨牌那样放在网格中吗?我不这么认为. Zydsg ...

  8. django--orm关系字段(ForeignKey、OneToOneField、ManyToManyField)详解

    django中的关系字段 1.ForeignKey字段,即外键字段,对应一对多的情况,列如:一本书对应一个出版社,一个出版社可对应多本书. 2.ManyToManyFiled字段,即多对多字段,对应数 ...

  9. 实现纯英文string的逆序输出

      第一种方法: using namespace std; void Reverse(string &a) { int n = a.size(); char b; ;i<n/;i++) ...

  10. mysql 自带的性能压力测试工具

    mysqlslap -h127.0.0.1 -uroot -p --concurrency=100 --iterations=1 --auto-generate-sql --auto-generate ...