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 ...
 
随机推荐
- SpringMvc入门三----控制器
			
在传统的Spring MVC开发方法中,必须在Bean配置文件中为每个控制器类配置实例和请求映射和让每个控制器类去实现或者扩展特定于框架的接口或者基类,不够灵活. 如果Spring MVC可以自动侦测 ...
 - QT 信号与槽连接
			
转帖 http://www.cnblogs.com/cnhome/archive/2009/10/01/1577277.html 信号(SIGNAL)和槽(SLOT)是Qt编程的一个重要部分.这个机制 ...
 - windows内存映射学习及帮助类实现
			
本文通过创建文件内存映射类,学习windows内存映射相关知识:创建内存映射文件后,可以按照内存操作方式操作文件:支持32位程序处理超过4G大小的文件. 感谢http://blog.csdn.net/ ...
 - UIKit,Core Data , Core Graphics, Core Animation,和OpenGLES框架
			
iOS的主要框架介绍 框架是一个目录,这个目录包含了共享库,访问共享库里代码的头文件,和其它的图片和声音的资源文件.一个共享库定义的方法或函数可以被应用程序调用. IOS提供了很多你可以在应用程序 ...
 - Java包的命名规则
			
按照惯例,包申明遵循特定的格式.虽然不是严格要求的Java语法,如果不遵循格式要求,大多数的Java认为你是不懂Java. 从右到左的顺序是: 1.systaxExample表明包的本地名称. 2.e ...
 - Vue.js 2.0版
			
Vue.js 2.0版升级,更改了好多方法或指令 new Vue({ el:'#demo', data:{ msg:"vue2.0" } }) v-model lazy numbe ...
 - CENTOS6.2系统日志rsyslog替换默认的日志服务syslog 转载自http://www.phpboy.net/linux/648.html
			
最近遇到配置centos 6.2的sshd及sftp日志,发现/etc/syslog.conf文件不存在, 然后: #rpm -qa | grep syslog 出来的是 rsyslog-5.8.10 ...
 - openerp经典收藏 深入理解对象(转载)
			
深入理解对象(转载) 原文地址:http://shine-it.net/index.php/topic,2159.0.htmlhttp://blog.sina.com.cn/s/blog_57ded9 ...
 - openerp学习笔记 调用工作流
			
获取工作流服务:wf_service = netsvc.LocalService("workflow")删除对象对应记录的工作流:wf_service.trg_delete(uid ...
 - 第一个C#应用 【搜索软件】
			
搜索软件V1.0 [附软件截图][http://pan.baidu.com/s/1mihEbe4] 设备搜索:支持广播搜索[local search],指定ip[range search]搜索,直接w ...