POJ3258 River Hopscotch
来源:互联网 发布:项目经理薪水知多少 编辑:程序博客网 时间:2024/06/05 15:37
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 2214112117
Sample Output
4
Hint
Source
——————————————————————————————————
题目的意思是给出n个数,取走m个要求两两之间(以及和岸的)最小值最大是多少?
思路:二分最小距离+验证
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#include <string>#include <vector>using namespace std;#define inf 0x3f3f3f3f#define LL long longint a[100005];int n,m,mx;bool ok(int x){ int cnt=0; int sum=0; for(int i=1;i<n;i++) { sum+=a[i]-a[i-1]; if(sum<x) cnt++; else sum=0; } if(cnt<=m) return 1; return 0;}int main(){ while(~scanf("%d%d%d",&mx,&n,&m)) { a[0]=0,a[n+1]=mx; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); } n+=2; sort(a,a+n); int l=0,r=1000000000; int ans; while(l<=r) { int mid=(l+r)/2; if(ok(mid)) { l=mid+1; ans=mid; } else { r=mid-1; } } printf("%d\n",ans); } return 0;}
- 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
- River Hopscotch(二分POJ3258)
- POJ3258--------River Hopscotch
- poj3258 River Hopscotch(二分)
- 【NOIP2015TGD2T1】poj3258 River Hopscotch
- POJ3258 River Hopscotch
- POJ3258 River Hopscotch
- POJ3258-River Hopscotch
- POJ3258-River Hopscotch二分
- 【二分法】POJ3258-River Hopscotch
- ListView添加头部移动到屏幕顶端
- std::function与std::bind 函数指针
- self-sizing cell的一个问题
- <address>联系地址信息</address>
- Jupyter Notebook 转pdf 中文处理
- POJ3258 River Hopscotch
- JS 数组去重!!! 一篇不怎么靠谱的 "深度" 水文
- 移动端、手机调用百度地图 Demo
- Deep learning:三十四(用NN实现数据的降维)
- 多项目、依赖项目在Build APK时出现duplicate entry错误
- mongo中save和insert区别
- android 应用的组件化
- iOS集成友盟分享
- AngularJs选择框