poj 3258"River Hopscotch"(二分搜索+最大化最小值问题)
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"(二分搜索+最大化最小值问题)的更多相关文章
- 二分搜索 POJ 3258 River Hopscotch
题目传送门 /* 二分:搜索距离,判断时距离小于d的石头拿掉 */ #include <cstdio> #include <algorithm> #include <cs ...
- [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6697 Accepted: 2893 D ...
- POJ 3258 River Hopscotch(二分查找答案)
一个不错的二分,注释在代码里 #include <stdio.h> #include <cstring> #include <algorithm> #include ...
- poj 3258 River Hopscotch 题解
[题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值 ...
- 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 ...
- poj 3258 River Hopscotch(二分搜索之最大化最小值)
Description Every year the cows hold an ≤ L ≤ ,,,). Along the river between the starting and ending ...
- POJ 3258 River Hopscotch(二分法搜索)
Description Every year the cows hold an event featuring a peculiar version of hopscotch that involve ...
随机推荐
- Delphi 在dbgrideh中表格输入数据时有效性的检查(转)
在数据库系统设计中经常要用到在表格中进行数据录入,如何判断在数据导入时的数据有效性呢?下面介绍几种常用的方法与大家交流. 方法一:Dbgrid是与Table,在Table的Column的OnSetTe ...
- time模块 转换关系图
import time t = time.time() #获取目前时间 t_struck = time.localtime(t) #time.gmtime() utc时区 t_str = time.s ...
- Jetson TX1 install py-faster-rcnn
Install py-faster-rcnn following the official version https://github.com/rbgirshick/py-faster-rcnn ...
- 【数学建模】day11-典型相关分析
这与主成分分析有点相似. 0. 基本思想主成分分析(PCA)是把原始有相关性变量,线性组合出无关的变量(投影),以利用主成分变量进行更加有效的分析.而典型相关分析(CCA)的思想是: 分析自变量组 X ...
- DRF 版本 认证
DRF的版本 版本控制是做什么用的, 我们为什么要用 首先我们要知道我们的版本是干嘛用的呢大家都知道我们开发项目是有多个版本的 当我们项目越来越更新~版本就越来越多我们不可能新的版本出了~以前旧的版本 ...
- Civil 3D 二次开发 翻转曲面高程分析颜色
不解释,直接上代码及截图. [CommandMethod("RvsSEA")] public void ReverseSurfaceElevationAnalysis() { Ci ...
- 关于jQuery.when()用法
1.该方法在jQuery1.5开始被引入. 2.用法测试 a. var url1 = "/resource/ar/hometab/index_tab_games.json", ur ...
- 微信小程序——报错汇总
tabBar.list[2].selectedIconPath 文件不存在 很明显是文件名错了,定义的my-acive,少写了个t,眼睛出问题了~ module "static/vant/c ...
- 洛谷P1916 小书童——蚂蚁大战
题目背景 小A在你的帮助下,开始“刷题”,他在小书童里发现了一款叫“蚂蚁大战”(又称蛋糕保卫战)的游戏.(你懂得) 题目描述 游戏中会出现n只蚂蚁,分别有a1,a2……an的血量,它们要吃你的蛋糕.当 ...
- 洛谷P3381 最小费用最大流
费用流板子 还是一道板子题..先练练手 #include <bits/stdc++.h> #define INF 0x3f3f3f3f #define full(a, b) memset( ...