POJ 3258 River Hopscotch<二分>
来源:互联网 发布:替代windows cmd 编辑:程序博客网 时间:2024/06/06 19:53
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, Lunits 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 2214112117
Sample Output
4
Hint
#include<cstdio>#include<algorithm>using namespace std;int l,n,m;int a[50005];int f(int mid){ int cou=0,sum=0; for(int i=0;i<n;i++) { if(a[i]-sum<mid)//如果小于,就舍去当前的石头 continue; sum=a[i]; cou++; } if(l-a[n-1]>=mid)//判断最后一个石头能不能留下来 cou++; if(cou>=n-m+1) return 1; else return 0;}int main (){ while(~scanf("%d%d%d",&l,&n,&m)){ for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); int ll=0,r=l,ans; while(ll<=r){ int m=(ll+r)/2; if(f(m)) {ll=m+1;ans=m;}//满足条件,继续往后寻找. else { r=m-1; } } printf("%d\n",ans); }}
- POJ 3258 River Hopscotch 二分
- POJ 3258 River Hopscotch 二分
- poj-3258-River Hopscotch-二分
- River Hopscotch - POJ 3258 二分
- 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
- POJ 3258 River Hopscotch (二分)
- POJ 3258 River Hopscotch(二分)
- C++ 第三章标准库类型
- 欢迎使用CSDN-markdown编辑器
- JQuery和JS
- 学习IoC依赖倒置原则
- 180°舵机的使用步骤
- POJ 3258 River Hopscotch<二分>
- 解题报告:HDU_6035 Colorful Tree 树上计数
- golang https server
- 细说 ASP.NET Cache 及其高级用法
- 机器学习六 决策树
- onreadystatechange被多次调用的原因
- 项目采取实施和开发分离
- 系列 《使用sklearn进行集成学习——理论》 《使用sklearn进行集成学习——实践》 目录 1 Random Forest和Gradient Tree Boosting参数详解 2 如何调参?
- oracle数据库 练习一