River Hopscotch(二分最大值)
来源:互联网 发布:软件质量保证的重要性 编辑:程序博客网 时间:2024/05/18 14:26
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
Line 1: Three space-separated integers: L, N, and M
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
Line 1: A single integer that is the maximum of the shortest distance a cow has to jump after removing M rocks
Sample Input
25 5 2
2
14
11
21
17
Sample Output
4
Hint
Before removing any rocks, the shortest jump was a jump of 2 from 0 (the start) to 2. After removing the rocks at 2 and 14, the shortest required jump is a jump of 4 (from 17 to 21 or from 21 to 25).
给出一堆石头坐标,一只青蛙xjb来回跳,最多略过m个石头,问他跳的过程中,最短的一次跳跃距离最大能是多少。
直接二分枚举,判断也很简单,每次跳的时候略过石头数加起来,与m比较。
#include<cstdio>#include<cstring>#include<iostream>#include<queue>#include<vector>#include<algorithm>#include<string>#include<cmath>#include<set>#include<map>#include<vector>#include<stack>#include<utility>#include<sstream>using namespace std;typedef long long ll;const int inf = 0x3f3f3f3f;const int maxn = 1005;int l,m,n;int a[50010];bool check(int x){ int pre = 0; for(int i = 1;i <= n - m;i++) { pre = lower_bound(a + pre,a + 1 + n,a[pre] + x) - a; if(pre > n)return false; } if(l - a[pre] < x)return false; return true;}int main(){ #ifdef LOCAL freopen("C:\\Users\\巍巍\\Desktop\\in.txt","r",stdin); //freopen("C:\\Users\\巍巍\\Desktop\\out.txt","w",stdout); #endif // LOCAL scanf("%d%d%d",&l,&n,&m); a[0] = 0;a[n + 1] = l; for(int i = 1;i <= n;i++) scanf("%d",&a[i]); sort(a + 1,a + 1 + n); int l = 0,r = inf; while(r - l > 1) { int mid = (l + r)/2; if(check(mid)) l = mid; else r = mid; } printf("%d\n",l); return 0;}
- River Hopscotch(二分最大值)
- River Hopscotch(二分)
- poj3258--River Hopscotch(二分)
- POJ3258 River Hopscotch(二分)
- POJ3528:River Hopscotch(二分)
- poj 3258 River Hopscotch(二分答案)
- poj 3258 River Hopscotch(二分搜索)
- POJ 3258 River Hopscotch (二分)
- poj 3258 River Hopscotch(二分+贪心)
- POJ 3258 River Hopscotch(二分 跳河)
- POJ 3258 River Hopscotch (二分搜索)
- POJ 3258 River Hopscotch(二分)
- POJ 3258 River Hopscotch(二分)
- poj-3258 River Hopscotch (二分)
- POJ 3258 River Hopscotch (二分经典)
- POJ 3258-River Hopscotch(二分+贪心)
- 【POJ】3258 - River Hopscotch(二分)
- POJ3258——River Hopscotch(二分)
- PhantomJS网页截图
- Android studio如何使用SVN进行版本控制?
- iOS类别和类扩展
- Linux 3.10完全无滴嗒特性详解
- C#中方法、类等的默认访问修饰符~
- River Hopscotch(二分最大值)
- 慕课网----大话PHP设计模式 五(原型模式,装饰器模式,迭代器模式,代理模式)
- Android Studio创建库项目及引用
- Android LCD(一):LCD基本原理篇
- Shader编程笔记(二)<新手入门> 固定管线Shader
- Android酷炫实用的开源框架(UI框架)
- 如何使用 volatile, synchronized, final 进行线程间通信
- awk循环处理文本进行统计
- ubuntu svn命令行下使用