POJ 3258 River Hopscotch (二分法)
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 toM 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<cstdio>
- #include<algorithm>
- using namespace std;
- int l,m,n,a[+],i,le,ri,ans;
- int f(int x,int y, int m)
- {
- while(x<=y)
- {
- int mid = x+(y-x)/;
- int key=,num=;
- for(i = ; i <= n+ ; i++)
- {
- if((num+=a[i]-a[i-])<= mid)
- {
- key++;
- }
- else
- {
- num=;
- }
- }
- if(key <= m)
- {
- x=mid+;
- }
- else
- {
- y=mid-;
- }
- }
- return x;
- }
- int main()
- {
- while(scanf("%d %d %d",&l,&n,&m)!=EOF)
- {
- le=;
- ri=l;
- a[]=;
- a[n+]=l;
- for(i = ; i <= n ; i++)
- {
- scanf("%d",&a[i]);
- }
- sort(a,a+n+);
- for(i=;i<=n+;i++)
- {
- le=min(le,a[i]-a[i-]);
- }
- ans=f(le,ri,m);
- printf("%d\n",ans);
- }
- }
POJ 3258 River Hopscotch (二分法)的更多相关文章
- POJ 3258 River Hopscotch(二分法搜索)
Description Every year the cows hold an event featuring a peculiar version of hopscotch that involve ...
- 二分搜索 POJ 3258 River Hopscotch
题目传送门 /* 二分:搜索距离,判断时距离小于d的石头拿掉 */ #include <cstdio> #include <algorithm> #include <cs ...
- 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(二分+贪心)
题目:http://poj.org/problem?id=3258 题意: 一条河长度为 L,河的起点(Start)和终点(End)分别有2块石头,S到E的距离就是L. 河中有n块石头,每块石头到S都 ...
- POJ 3258 River Hopscotch 二分枚举
题目:http://poj.org/problem?id=3258 又A一道,睡觉去了.. #include <stdio.h> #include <algorithm> ]; ...
随机推荐
- wamp2.5版本配置多端口虚拟主机
1.保证httpd.conf下 LoadModule php5_module "D:/E/php/wamp/bin/php/php5.5.12/php5apache2_4.dll" ...
- iOS Testing with Xcode 阅读笔记
官方文档直通车 Performance Testing A baseline is a combination of the average time performance in ten runs ...
- Jquery | 基础 | 慕课网 | 元素选择器
getElementsByTagName方法得到页面所有的<div>元素 var divs = document.getElementsByTagName('div'); 与 同样的效果, ...
- ssm框架下实现文件上传
1.由于ssm框架是使用Maven进行管理的,文件上传所需要的jar包利用pom.xml进行添加,如下所示: <properties> <commons-fileupload.v ...
- python之小技巧积累
交换a和b的值:a=11b=22#引进第三个变量交换a和b的值# c=a#把a给c,现在c是11# a=b#把b给a,现在a是22# b=c#把c给b,现在b是11 #不引进第三个变量,交换a和b的值 ...
- 什么是Servlet容器?(分析很到位)
在本文中,我写了一些关于Web服务器.Servlet容器以及它与JVM的关系的基本概念.我想表达的是,Servlet容器也仅仅不过是一个Java程序. 1. 什么是Web服务器? 想要知道什么是Ser ...
- jsonp对付同源策略
当 协议不同或者域名/ip不同或者端口号不同 , 都不算是同源 这时候 源生的ajax 就不能进行数据请求了 JSONP json with padding 在平时的开发中也发现了 ,当我们请求 ...
- 【js数据结构】图的深度优先搜索与广度优先搜索
图类的构建 function Graph(v) {this.vertices = v;this.edges = 0;this.adj = []; for (var i = 0; i < this ...
- jsp <%@ include %> 例子
<%@ include %>:所有代码包含进来之后一起进行处理,最终编译成一个servlet. jsp文件中添加top和bottom.jsp页面 empList.jsp <%@ pa ...
- laravel关联用户
参考文档:模型关联-反向关联 belongsToor 模型层 app/Post.php public function user() { return $this->belongsTo('\Ap ...