POJ 3258:River Hopscotch (最大化最小值)
【题意】
牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离,
现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值。
Sample Input
25 5 2
2
14
11
21
17
Sample Output
4
分析:其实这个和Agressive Cows这道题差不多,只要把起点与终点加入到数组中,然后留下找(N-M+2)个位置之间的最大值,类比与Agressive cows的M;
具体题解可看Agressive cows AC代码:
#include<stdio.h>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int n,m,l;
int a[];
bool cmp (int x,int y)
{
return x<y;
}
bool C(int d)
{
int last=;
for(int i= ; i<(n-m+) ; i++)
{
int crt=last+;
while(crt<n+&&a[crt]-a[last]<d)
crt++;
if(crt==n+)
return false;
last = crt;
}
return true; }
int main()
{
scanf("%d%d%d",&l,&n,&m);
for(int i = ; i <= n ; i++)
scanf("%d",&a[i]);
a[n+]=l;
sort(a,a+n+,cmp);
int en=INF;
int st=; while(en-st>)
{
int mid=(st+en)/;
if(C(mid))
st=mid;
else
en=mid;
}
printf("%d\n",(st+en)/);
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 ...
- POJ3285 River Hopscotch(最大化最小值之二分查找)
POJ3285 River Hopscotch 此题是大白P142页(即POJ2456)的一个变形题,典型的最大化最小值问题. C(x)表示要求的最小距离为X时,此时需要删除的石子.二分枚举X,直到找 ...
- 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(二分查找答案)
一个不错的二分,注释在代码里 #include <stdio.h> #include <cstring> #include <algorithm> #include ...
- 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"(二分搜索+最大化最小值问题)
传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 块岩石,从中去掉任意 M 块后,求相邻两块岩石最小距离最大是多少? 题解 ...
随机推荐
- 2014年Linux 和开源技术回顾盘点
ZDNet科技观察家StevenJ.Vaughan-Nichols在年终发表了对Linux和开源技术这一年跌宕起伏的总结,细数这一年中的惊喜和不堪. 2014Linux之殇 “心脏出血(Heartbl ...
- css总结20:TCP通信协议WebSocket
HTML5 WebSocket 1 介绍: WebSocket是HTML5开始提供的一种在单个 TCP 连接上进行全双工通讯的协议. 在WebSocket API中,浏览器和服务器只需要做一个握手的动 ...
- backquote
character (`) A backquote or backtick. echo 'date' date echo `date` 2015年 07月 03日 星期五 16:11:13 CST j ...
- SQL之DML
DML(Data Manipulation Language)数据操纵语言statements are used for managing data within schema objects. 由D ...
- POJ2442 Sequence(堆的骚操作)
Description Given m sequences, each contains n non-negative integer. Now we may select one number fr ...
- tornado+nginx上传视频文件
[http://arloz.me/tornado/2014/06/27/uploadvideotornado.html] [NGINX REFRER:Nginx upload module] 由于to ...
- CreateExcel 导出Excel
public class CreateExcel { /// <summary> /// 用Excel组件导出Excel文件 /// </summary> /// <pa ...
- linux学习之路(4)
用户身份与文件权限 通过uid来区分: 管理员 UID 为 0:系统的管理员用户. 系统用户 UID 为 1-999: Linux 系统为了避免因某个服务程序出现漏洞而被黑客提 权至整台服务器,默认 ...
- (转)深入研究MiniMVC之后续篇
今天在园子看到<深入研究 蒋金楠(Artech)老师的 MiniMvc(迷你 MVC),看看 MVC 内部到底是如何运行的>之后,本来是不打算开博来续这个后传,不过,在那边回了个评论之后, ...
- Kotlin 区间的一些小注意
1:步进 step 在kotlin 中区间通过循环可以实现每隔几个输出. 比如1..100,我每隔3个输出: fun main(args:Array<Stting>) { .. step) ...