POJ 3258 Cross The Rive
2015-07-28 20:14
330 查看
B - Cross The River
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice POJ
3258
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
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
Sample Output
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。
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice POJ
3258
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
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).
二分步距,然后根据步距去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; }
相关文章推荐
- 输入输出流7.28学习笔记
- @echo off 批处理
- 关于PostgrepSQL
- windows 下安装mongdb
- 实现文字渐变的效果
- Block
- 线段树_FZU_1921
- 数据结构实验:连通分量个数
- Java(07-28)学习总结
- Java画陆龟
- 【试水CAS-4.0.3】第09节_CAS服务端RememberMe
- CloudStack 4.5 安装笔记
- HDU 5323 SOLVE THIS INTERESTING PROBLEM 爆搜
- 获取进程CPU占用率 -- NtQuerySystemInformation
- AndroidManifest.xml
- Search for a Range
- [hdu5323]复杂度计算,dfs
- eclipse下安装tomcat以及可能遇到的404问题
- hdu杭电4006 The kth great number【优先队列】
- linux中的权限对于文件和目录的重要性