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> ]; ... 
随机推荐
- 分布式集群环境下,如何实现session共享四(部署项目测试)
			这是分布式集群环境下,如何实现session共享系列的第四篇.在上一篇:分布式集群环境下,如何实现session共享三(环境搭建)中,已经准备好了相关的环境:tomcat.nginx.redis.本篇 ... 
- 即时编译(JIT)
			即时编译(JIT : just-in-time compilation): 指计算机领域里,即时编译也被成为动态翻译,是一种通过在运行时将字节码翻译为机器码,从而改善字节码编译语言性能的技术 即时编译 ... 
- 跟我一起玩Win32开发(4):创建菜单
			也不知道发生什么事情,CSDN把我的文章弄到首页,结果有不少说我在误人子弟,是啊,我去年就说过了,如果你要成为砖家级人物,请远离我的博客,我这个人没什么特长,唯一厉害的一点就是不相信权威,鄙视砖家,所 ... 
- scikit-learning教程(三)使用文本数据
			使用文本数据 本指南的目标是探讨scikit-learn 一个实际任务中的一些主要工具:分析二十个不同主题的文本文档(新闻组帖子)集合. 在本节中,我们将看到如何: 加载文件内容和类别 提取适用于机器 ... 
- Codeforces Round #402 (Div. 2) D
			Description Little Nastya has a hobby, she likes to remove some letters from word, to obtain another ... 
- php多文件上传类(含示例)
			在网上看到一个比较好的多文件上传类,自己改良了下,顺便用js实现了多文件浏览,php文件上传原理都是相同的,多文件上传也只是进行了循环上传而已,当然你也可以使用swfupload进行多文件上传! &l ... 
- 2. UITest相关APIs
			1. XCUIApplication 这是你正在测试的应用的代理.它能让你启动应用,这样你就能执行测试了.它每次都会新起一个进程,这会多花一些时间,但是能保证测试应用时的状态是干净的,这样你需要处理的 ... 
- ES-Apache Lucene
			前言 在介绍Lucene之前,我们来了解相关的历史. 有必要了解的Apache Apache软件基金会(也就是Apache Software Foundation,简称为ASF)是专门为运作一个开源软 ... 
- canvas基础绘制-arc
			<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ... 
- 【学习笔记】深入理解js原型和闭包(13)——【作用域】和【上下文环境】
			上文简单介绍了作用域,本文把作用域和上下文环境结合起来说一下,会理解的更深一些. 如上图,我们在上文中已经介绍了,除了全局作用域之外,每个函数都会创建自己的作用域,作用域在函数定义时就已经确定了.而不 ... 
