poj3258--River Hopscotch(二分)
来源:互联网 发布:网络爸爸是什么意思 编辑:程序博客网 时间:2024/05/12 22:18
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 distanceDi 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 ofM 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 2214112117
Sample Output
4
Hint
Source
#include <cstdio>#include <cstring>#include <algorithm>using namespace std ;int c[60000] ;int n , m ;int solve(int min1){ int num = 0 , last , i ; last = 0 ; for(i = 1 ; i < n+2 ; i++) { if( c[i] - last >= min1 ) { last = c[i] ; } else { num++ ; } } if( last != c[n+1] ) num++ ; if( num <= m ) return 1 ; return 0;}int main(){ int l , i , j , low , mid , high , last ; while( scanf("%d %d %d", &l, &n, &m) != EOF ) { c[0] = 0 ; for(i = 1 ; i <= n ; i++) { scanf("%d", &c[i]) ; } c[n+1] = l ; sort(c+0,c+(n+2)) ; low = l ; for(i = 1 ; i < n+2 ; i++) { low = min( low,c[i]-c[i-1] ) ; } high = l ; while( low <= high ) { mid = ( low + high ) / 2 ; if( solve(mid) ) { last = mid ; low = mid + 1 ; } else high = mid - 1 ; } printf("%d\n", last) ; } return 0;}
- poj3258--River Hopscotch(二分)
- POJ3258 River Hopscotch(二分)
- POJ3258 River Hopscotch二分
- POJ3258:River Hopscotch(二分)
- River Hopscotch(二分POJ3258)
- poj3258 River Hopscotch(二分)
- POJ3258-River Hopscotch二分
- Poj3258 River Hopscotch 二分
- POJ3258 River Hopscotch 二分
- POJ3258——River Hopscotch(二分)
- POJ3258 River Hopscotch 二分搜索
- POJ3258 River Hopscotch(二分+贪心)
- POJ3258:River Hopscotch(二分法)
- (POJ3258)River Hopscotch <二分法>
- POJ3258,River Hopscotch,二分加贪心
- 【POJ3258】River Hopscotch 二分答案,贪心check
- POJ3258-River Hopscotch-二分+贪心【最小值最大化】
- (最大化最小值),poj3258,River Hopscotch
- 圆球立体jquery标签云代码分享啦带demo测试无错要的下载吧
- C#按上下键切换上下文本框
- 模板模式(Template Method)
- selenium python向富文本框中输入内容
- ContentType
- poj3258--River Hopscotch(二分)
- 大根堆 小根堆 找中位数
- Java集合
- 红黑树详解(源码+图示)
- mysql安装一 rpm包安装
- Nodejs创建HTTPS服务器
- specular高光贴图
- invalid use of incomplete type struct 或者是class的解决办法
- 揭开Socket编程的面纱