二分搜索 POJ 3258 River Hopscotch
/*
二分:搜索距离,判断时距离小于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的更多相关文章
- POJ 3258 River Hopscotch
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11031 Accepted: 4737 ...
- POJ 3258 River Hopscotch (binarysearch)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5193 Accepted: 2260 Descr ...
- POJ 3258 River Hopscotch(二分答案)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21939 Accepted: 9081 Desc ...
- [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6697 Accepted: 2893 D ...
- poj 3258 River Hopscotch 题解
[题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值 ...
- poj 3258 River Hopscotch(二分搜索之最大化最小值)
Description Every year the cows hold an ≤ L ≤ ,,,). Along the river between the starting and ending ...
- poj 3258"River Hopscotch"(二分搜索+最大化最小值问题)
传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 块岩石,从中去掉任意 M 块后,求相邻两块岩石最小距离最大是多少? 题解 ...
- POJ 3258 River Hopscotch(二分法搜索)
Description Every year the cows hold an event featuring a peculiar version of hopscotch that involve ...
- poj 3258 River Hopscotch(二分+贪心)
题目:http://poj.org/problem?id=3258 题意: 一条河长度为 L,河的起点(Start)和终点(End)分别有2块石头,S到E的距离就是L. 河中有n块石头,每块石头到S都 ...
随机推荐
- vim状态栏的扩充
将以下内容添加到~/.vimrc文件中: set statusline= set statusline+=%7*\[%n] " ...
- Spring Boot实现跨域(转)
一.方法: 服务端设置Respone Header头中Access-Control-Allow-Origin 配合前台使用jsonp 继承WebMvcConfigurerAdapter 添加配置类 二 ...
- Ubuntu 16.04安装Atom(加强版文本工具)
安装: sudo add-apt-repository ppa:webupd8team/atom sudo apt-get update sudo apt-get install atom 或者直接上 ...
- Ubuntu 16.04安装Ubuntu After Install工具实现常用软件批量安装
这个软件集成了常用且好用的软件,且只需要选择需要的软件之后自动安装好,不需要额外设置. 安装: sudo add-apt-repository ppa:thefanclub/ubuntu-after- ...
- java生成xml
import java.io.File;import java.io.FileOutputStream;import java.text.SimpleDateFormat;import java.ut ...
- spring SSH整合
1 导入三大框架依赖的包: 2 配置web.xml: 增加spring的OpenSessionInView过滤器让Spring管理Session保证Session在一个完整的请求过程是开着的,要配置S ...
- 【智能路由器】让MT7620固件openwrt支持USB
[智能路由器]系列文章连接 http://blog.csdn.net/u012819339/article/category/5803489 首先确定硬件有USB,这个得检查板子是否引出了usb口,一 ...
- IOS推断是否安装微信qq
BOOL weicaht = [[UIApplicationsharedApplication]canOpenURL:[NSURLURLWithString:@"mqqapi://" ...
- ZOJ 1806 (小数高精度)
题意:八进制小数转化成十进制的小数. 0.d1d2d3 ... dk [8] = 0.D1D2D3 ... Dm [10] 例: 0.75 [8] = 7*8^-1+5*8^-2 = ( 5/8 + ...
- HTML5开发移动web应用——SAP UI5篇(6)
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...