POJ 3258Cross The Rive
来源:互联网 发布:网站源码小偷程序 编辑:程序博客网 时间:2024/06/11 01:49
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 Difrom 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
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).
二分步距,然后根据步距去remove stones,检验是否小于m。
#include <iostream>#include<cstdio>#include<algorithm>using namespace std;long long a[50010],b[50010];int len,n,mm;int check(long long d){ int i,j,ans=0; for (i=0;i<=n+1;i++) a[i]=b[i]; for (i=1;i<=n+1;i++){ if (a[i]-a[i-1]<d){ if (i-1==0) {a[i]=0;ans++;continue;}; if (i==n+1) {ans++;continue;}; ans++;a[i]=a[i-1]; } } if (ans>mm) return 0; return 1;}long long bse(){ long long l,r,m,i,j; l=1;r=len;m=(l+r)/2; while (l<r){ if (check(m)) l=m+1; else r=m; m=(l+r)/2; } if (!check(m)) m--; return m;}int main(){ int i,j; scanf("%d %d %d",&len,&n,&mm); b[0]=0;b[n+1]=len; for (i=1;i<=n;i++) scanf("%lld",&b[i]); sort(b,b+n+2); cout<<bse()<<endl; return 0;}
- POJ 3258Cross The Rive
- poj 1700 Crossing Rive(贪心)
- The Cross
- poj 3467 Cross Counting
- hdu3669 Cross the Wall
- Cross the Wall UVALive
- POJ 3467 Cross Counting 可能会
- POJ 1257 Cross-stitch. 笔记
- Cross compile the kernel module
- The Psychology of Cross Country
- hdu 3931 Cross the Fire
- hdu 3931 Cross the Fire
- The Psychology of Cross Country
- hdu 3369 Cross the Wall
- The Psychology of Cross Country
- Problem D. Cross the maze
- hdu 3669 Cross the Wall
- HDOJ 3669 Cross the Wall
- AndroidManifest.xml
- ALV OO: 最简单的ALV OO实例-自定义容器
- Hadoop集群搭建
- android 把文件传到/system/framework目录下
- OC协议创建的步骤以及设置新代理人的步骤
- POJ 3258Cross The Rive
- java基础之方法的多态
- Block
- HDU 2546 饭卡
- DirectFB常用接口
- 线段树_FZU_1921
- Java对象序列化和反序列化
- ASCⅡ码转换
- HDOJ 1896 Stones(优先队列)