POJ 3258
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 5961 | Accepted: 2579 |
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
Source
二分搜索
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std; #define maxn 50005 int L,n,m;
int dis[maxn]; bool judge(int x) {
int now = ; int t = m;
for(int i = ; i <= n; i++) {
if(dis[i] - now < x) {
--t;
} else {
now = dis[i];
}
} if(L - now < x) {
--t;
} return t >= ;
} void solve() {
int r = L,l = ; while(l < r) {
int mid = (l + r + ) >> ;
if(judge(mid)) {
l = mid;
} else {
r = mid - ;
}
} printf("%d\n",l);
} int main() {
// freopen("sw.in","r",stdin); scanf("%d%d%d",&L,&n,&m);
for(int i = ; i <= n; i++) {
scanf("%d",&dis[i]);
} sort(dis + ,dis + n + ); solve(); return ;
}
POJ 3258的更多相关文章
- poj 3258 River Hopscotch 题解
[题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值 ...
- 二分搜索 POJ 3258 River Hopscotch
题目传送门 /* 二分:搜索距离,判断时距离小于d的石头拿掉 */ #include <cstdio> #include <algorithm> #include <cs ...
- E - River Hopscotch POJ - 3258(二分)
E - River Hopscotch POJ - 3258 Every year the cows hold an event featuring a peculiar version of hop ...
- 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> ]; ...
- POJ 3258(二分求最大化最小值)
题目链接:http://poj.org/problem?id=3258 题目大意是求删除哪M块石头之后似的石头之间的最短距离最大. 这道题目感觉大致代码写起来不算困难,难点在于边界处理上.我思考边界思 ...
- POJ 3258 River Hopscotch(二分答案)
嗯... 题目链接:http://poj.org/problem?id=3258 一道很典型的二分答案的题目,和跳石头太像了!! 这道题的题目很显然,求最小中的最大值,注意这道题石头的位置不是从小到大 ...
- poj 3258 River Hopscotch 【二分】
题目真是不好读,大意例如以下(知道题意就非常好解了) 大致题意: 一条河长度为 L,河的起点(Start)和终点(End)分别有2块石头,S到E的距离就是L. 河中有n块石头,每块石头到S都有唯一的距 ...
- poj 3258 3273
poj3258 题目 (最大化最小值)(最小值最大化) 题意:牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离,现在去掉M块石头,要求去掉M块石 ...
- POJ 3258 River Hopscotch(二分法搜索)
Description Every year the cows hold an event featuring a peculiar version of hopscotch that involve ...
随机推荐
- js中字符和数组一些基本算法题
最近在刷 fcc的题,跟升级打怪一样,一关一关的过,还挺吸引我的.今天抽时间把 Basic Algorithm Scritping 这部分题做了,根据一些提示,还是比较简单的.有些题的处理方式 方法 ...
- 南阳理工oj88--汉诺塔(一)
题目链接.http://acm.nyist.net/JudgeOnline/problem.php?pid=88 #include <stdio.h> /* //测试一下49999和500 ...
- js 字符串“123”,变成整数123,不用parseInt 函数
var s = "123"; console.log(s.charAt(0)*100+s.charAt(1)*10+s.charAt(2)*1);
- YCM的安装与配置
花了好几天的时间,总算把YCM装上了.期间遇到了各种问题,主要还是因为刚进linux,对linux环境不熟, 命令资料等查了半天.当然,YCM也普遍被认为是一种安装配置复杂,但使用起来超简单的插件. ...
- 常用JS加密编码算法
//#region UTF8编码函数 function URLEncode(Str) { if (Str == null || Str == "") return "&q ...
- jQuery1.9 $.browser 的替代方法
jQuery 从 1.9 版开始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.support . 在更新的 2.0 版本中,将不再支持 IE 6/7/8. ...
- jQuery WIN 7透明弹出层效果
jQuery WIN 7透明弹出层效果,点击可以弹出一个透明层的jquery特效,插件可以调弹出框的宽度和高度,很不错的一个弹出层插件. 适用浏览器:IE8.360.FireFox.Chrome.Sa ...
- iphone document 图片存储和读取
转载自:http://longquan.iteye.com/blog/1669990 存: //此处首先指定了图片存取路径(默认写到应用程序沙盒 中) NSArray *paths = NSSearc ...
- (转)汉字转拼音HanziToPinyin
本文转载于:http://blog.csdn.net/zhangphil/article/details/47164665 Android系统本身自带有有将汉字转化为英文拼音的类和方法.具体的类就是H ...
- openerp学习笔记 自定义小数精度(小数位数)
小数位数标识定义: lx_purchase/data/lx_purchase_data.xml <?xml version="1.0" encoding="utf- ...