POJ--3258 River Hopscotch (最小值最大化C++)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 15273 | Accepted: 6465 |
Description
Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight river with a rock at the start and another rock at the end, L units away from the start (1 ≤ L ≤ 1,000,000,000). Along the river between the starting and ending rocks, N (0 ≤ N ≤ 50,000) more rocks appear, each at an integral distance Di from the start (0 < Di < L).
To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping only from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river.
Farmer John is proud of his cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rocks placed too closely together. He plans to remove several rocks in order to increase the shortest distance a cow will have to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he has enough resources to remove up to M rocks (0 ≤ M ≤ N).
FJ wants to know exactly how much he can increase the shortest distance *before* he starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow has to jump after removing the optimal set of M rocks.
Input
Lines 2..N+1: Each line contains a single integer indicating how far some rock is away from the starting rock. No two rocks share the same position.
Output
Sample Input
25 5 2
2
14
11
21
17
Sample Output
4
Hint
#include<iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
int a[50005];
int main()
{
int l,m,n;
while(~scanf("%d%d%d",&l,&n,&m))
{ for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]); }
a[0]=0;
a[n+1]=l;
sort(a+1,a+n+1);
int mid,low=0,r=l;
while(r>=low)
{
int tem=0,c=0;
mid=(low+r)/2;
for(int i=1;i<=n+1;i++)
{
if(mid>=a[i]-a[tem])
c++;
else
tem=i;
}
if(c>m)
r=mid-1;
else
low=mid+1;
// cout<<low<<" "<<mid<<" "<<r<<endl;
}
printf("%d\n",low);
}
}
POJ--3258 River Hopscotch (最小值最大化C++)的更多相关文章
- poj 3258"River Hopscotch"(二分搜索+最大化最小值问题)
传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 块岩石,从中去掉任意 M 块后,求相邻两块岩石最小距离最大是多少? 题解 ...
- 二分搜索 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 题解
[题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有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 ...
随机推荐
- StringBulider简单用法
StringBuild的是个动态对象,可直接拼加上字符串:而string对象的步骤:先初始化对象并赋值了,而后在拼加字符串时,先要创建需要拼加的字符串,然后再拼加,所以这就是StirngBuild远比 ...
- XtraBackup应用说明(支持TokuDB)
背景: 关于物理备份工具xtrabackup的一些说明可以先看之前写过的文章说明:XtraBackup 安装使用和xtrabackup 使用说明(续),本篇文章将介绍xtrabackup在使用中的注意 ...
- 弹性伸缩布局-flex
弹性伸缩布局-flex 引言:本文主要参照阮一峰的网络日志 .郭锦荣的博客总结完成. 正文: 布局的传统解决方案,基于盒状模型,依赖 display 属性 + position属性 + float属性 ...
- OpenCms模块创建图解
登录OpenCms后,切换到"管理(Administration)"视图,点击"模块管理",这时窗口显示已安装模块的列表. 确定当前不在"online ...
- fineui webform
基于 jQuery 的专业 ASP.NET WebForms/MVC 控件库
- 电脑重装系统按什么键进U盘PE
电脑重装系统按什么键进U盘PE... -------------------------- 各品牌电脑重装系统快捷按键进U盘PE: -------------------------- Dell电脑重 ...
- mySQl数据库的学习笔记
mySQl数据库的学习笔记... ------------------ Dos命令--先在记事本中写.然后再粘贴到Dos中去 -------------------------------- mySQ ...
- 【JBoss】数据库连接配置小结(转)
数据库驱动位置: %JBOSS_HOME%\server\default\lib目录下. 数据库配置文件位置:JBOSS_HOME\docs\examples\jca\XXXX-ds.xml < ...
- Andrew Ng机器学习课程笔记--week9(下)(推荐系统&协同过滤)
本周内容较多,故分为上下两篇文章. 本文为下篇. 一.内容概要 1. Anomaly Detection Density Estimation Problem Motivation Gaussian ...
- 问题: 数据流中位数 求解 时间复杂度度 java
今天练习了一题: 数据流中位数 问题描述:数字是不断进入数组的,在每次添加一个新的数进入数组的同时返回当前新数组的中位数. 案例: 持续进入数组的数的列表为:[1, 2, 3, 4, 5],则返回[1 ...