POJ3258--River Hopscotch(Binary Search similar to POJ2456)
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, Lunits 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<algorithm>
using namespace std;
int pos[];
int l,n,m; bool C(int d){
int last=;
for(int i=;i<n-m;i++){
int cur=last+;
while(cur<n&&pos[cur]-pos[last]<d)
cur++;
if(cur==n)
return false;
last=cur;
}
return true;
} int main(){
cin>>l>>n>>m;
for(int i=;i<n;i++){
cin>>pos[i];
}
pos[n++]=;
pos[n++]=l;
sort(pos,pos+n);
int lb=,ub=l+;
while(ub-lb>){
int mid=(ub+lb)/;
if(C(mid))
lb=mid;
else
ub=mid;
}
cout<<lb<<endl;
return ;
}
POJ3258--River Hopscotch(Binary Search similar to POJ2456)的更多相关文章
- POJ--3258 River Hopscotch (最小值最大化C++)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15273 Accepted: 6465 ...
- POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13598 Accepted: 5791 ...
- POJ3258 River Hopscotch —— 二分
题目链接:http://poj.org/problem?id=3258 River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total ...
- poj3258 River Hopscotch(二分最小值,好题)
https://vjudge.net/problem/POJ-3258 二分最小值,判断需要删去的点的个数,如果大于给定,则直接return 0,则说明该数需要再小. 最后注意,起点是0终点是l,起点 ...
- POJ3258 River Hopscotch
地址 别人的代码,自己边界总是控制不好,还不知道哪里错了!思维!这种问题代码越简洁反而越不容易错吧.. #include<stdio.h> #include<algorithm> ...
- POJ3258 River Hopscotch(二分最大化最小值)
题目链接:http://poj.org/problem?id=3258 题意:给n个石头,起点和终点也是两个石头,去掉这石头中的m个,使得石头间距的最小值最大. 思路:二分石头间的最短距离,每次贪心地 ...
- Algo: Binary search
二分查找的基本写法: #include <vector> #include <iostream> int binarySearch(std::vector<int> ...
- River Hopscotch(二分POJ3258)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9263 Accepted: 3994 Descr ...
- 96. Unique Binary Search Trees
题目: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For e ...
随机推荐
- IDEA 的主题设置
1.主题设置(Appearance& Behavior) 补充1:设置编辑区的主题 (1)IDEA提供了两个编辑区的主题,如下所示 (2)如果想要更多的主题效果,可以到 http://www. ...
- BZOJ1178或洛谷3626 [APIO2009]会议中心
BZOJ原题链接 洛谷原题链接 第一个问题是经典的最多不相交区间问题,用贪心即可解决. 主要问题是第二个,求最小字典序的方案. 我们可以尝试从\(1\to n\)扫一遍所有区间,按顺序对每一个不会使答 ...
- Latex基本用法
空格 需要使用 \qquad,\quad,\,应该是占位符和变量之间需要有{}相隔. $$ C_{1} \qquad {C_2} $$ $$ C_{1} \quad {C_2} $$ $$ C_{1} ...
- 论坛:获取当前原始请求中的远程IP地址
topic.setIpAddr(ServletActionContext.getRequest().getRemoteAddr());//当前原始请求中的远程IP地址
- 如何利用Photoshop进行快速切图
在UI设计中我们常常使用Ai来进行矢量图的绘制,然后导入Ps中进行设计.排版和导出. 在以前的版本中,切图一直是个很麻烦的事情,要么依托于脚本,要么手动一张张导出,很不方便,这种窘况在Photosho ...
- Maximum Product Subarray LT152
Given an integer array nums, find the contiguous subarray within an array (containing at least one n ...
- 前端-关于 Vue 和 React 区别的一些笔记
监听数据变化的实现原理不同 1.Vue 通过 getter/setter 以及一些函数的劫持,能精确知道数据变化,不需要特别的优化就能达到很好的性能 2.React 默认是通过比较引用的方式进行的,如 ...
- spring security 4.2后出现CouldnotverifytheprovidedCSRFtokenbecauseyoursessionwasnotfound
升级到spring security 4.2后,登录不了,出现下面的错误 WARN DefaultHandlerExceptionResolver:361 - Failed to bind reque ...
- Django 文章标签功能
使用第三方框架django-taggit为模型添加标签功能,此模块是一个可复用的应用 首先安装 https://github.com/alex/django-taggit 这是项目主页 pip ins ...
- NOIP水题测试(2017082401)
哈,水题测试又来了! 上次的水题简单吧! 答案是以单题形式发布的(旅行家的预算随后发布). 下面来看今天的题,还是水题. 时间限制:5小时 题目一:看上去就很水 题目二:比上面一题还水 题目三:数的划 ...