题目传送门

 /*
二分:搜索距离,判断时距离小于d的石头拿掉
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; typedef long long ll;
const int MAXN = 5e4 + ;
const int INF = 0x3f3f3f3f;
ll a[MAXN];
int n, m; bool check(ll d) {
int last = ; int cnt = ;
for (int i=; i<=n+; ++i) {
if (a[i] - a[last] <= d) cnt++;
else last = i;
}
return cnt > m;
} int main(void) { //POJ 3258 River Hopscotch
//freopen ("POJ_3258.in", "r", stdin); ll x;
while (scanf ("%I64d%d%d", &x, &n, &m) == ) {
a[] = ; a[n+] = x;
for (int i=; i<=n; ++i) {
scanf ("%I64d", &a[i]);
} sort (a, a+n+); ll l = , r = a[n+];
while (l <= r) {
ll mid = (l + r) >> ;
if (check (mid)) r = mid - ;
else l = mid + ;
}
printf ("%I64d\n", l);
} return ;
}

二分搜索 POJ 3258 River Hopscotch的更多相关文章

  1. POJ 3258 River Hopscotch

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

  2. POJ 3258 River Hopscotch (binarysearch)

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

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

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

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

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

  5. poj 3258 River Hopscotch 题解

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

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

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

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

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

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

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

  9. poj 3258 River Hopscotch(二分+贪心)

    题目:http://poj.org/problem?id=3258 题意: 一条河长度为 L,河的起点(Start)和终点(End)分别有2块石头,S到E的距离就是L. 河中有n块石头,每块石头到S都 ...

随机推荐

  1. 【Java集合】Java中集合(List,Set,Map)

    简介: 数组是大小固定的,并且同一个数组只能存放类型一样的数据(基本类型/引用类型),而JAVA集合可以存储和操作数目不固定的一组数据. 所有的JAVA集合都位于 java.util包中! JAVA集 ...

  2. Thinkphp5.0 视图view取值

    Thinkphp5.0 视图view取值 <!-- 获取控制器传递的变量 --> <li>{$age}</li> <!-- 获取服务器的信息 --> & ...

  3. 洛谷—— P1690 贪婪的Copy

    https://www.luogu.org/problem/show?pid=1690 题目描述 Copy从卢牛那里听说在一片叫yz的神的领域埋藏着不少宝藏,于是Copy来到了这个被划分为个区域的神地 ...

  4. Spring Cloud(5):Hystrix的使用

    熔断:类似生活中的保险丝,电流过大就会熔断 降级:类似生活中的旅行,行李箱只有那么大,所以要抛弃一些非必需的物品 熔断降级应用: 某宝双十一商品下单,用户量巨大,于是考虑抛弃相关商品推荐等模块,确保该 ...

  5. 选择器的使用(nth-child和nth-last-child选择器)

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta ...

  6. 001 Cisco router prewired

    Cisco router 预配: Router>en Router#config t Enter configuration commands, one per line.  End with ...

  7. Symantec Backup Exec部署手册

    转载  http://xiaxiaoguo.blog.51cto.com/858884/402810 Symantec Backup Exec部署手册 目录 1.Backup Exec 12.5安装. ...

  8. 字节序:Big Endian 和 Little Endian

    一.字节序 字节序,也就是字节的顺序,指的是多字节的数据在内存中的存放顺序. 在几乎所有的机器上,多字节对象都被存储为连续的字节序列.例如:如果C/C++中的一个int型变量 a 的起始地址是& ...

  9. C/C++综合測试题(四)

    又刷了一套题 这些题都是百度.阿里巴巴.腾讯.网易.新浪等公司的面试原题.有一定的难度.只是确实相当有水平.能够通过做题来查漏补缺. 11.以下代码的输出是什么? class A { public: ...

  10. cesm下载备注

    新版使用svn下载. 软件要求: The following are the external system and software requirements for installing and ...