River Hopscotch
来源:互联网 发布:淘宝上蜂蜜是真的吗 编辑:程序博客网 时间:2024/04/29 21:19
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 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 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<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<queue>#include<stack>#include<iostream>#include<algorithm>using namespace std; int a[5000001];int main (){int L,N,D;while(~scanf("%d%d%d",&L,&N,&D)){a[0] = 0;a[N+1] = L;for(int i = 1; i <= N; i++){scanf("%d",&a[i]);}sort(a,a+N+1);int l = 0,r = L,ans = 0;while(r-l >= 0){int mid = (l+r)/2;int count = 0,pre = 0;for(int i = 1; i <= N+1; i++){if(a[i] - a[pre] < mid){count++;}else{pre = i;}}if(count > D){r = mid-1;}else{l = mid+1;ans = mid;}}printf("%d\n",ans);}return 0;}
- River Hopscotch
- River Hopscotch
- River Hopscotch
- River Hopscotch
- River Hopscotch
- pku 3258 River Hopscotch
- pku3258 River Hopscotch
- pku 3258 River Hopscotch
- poj 3258 River Hopscotch
- Dichotomy poj River Hopscotch
- poj-3258 River Hopscotch
- River Hopscotch解题报告
- poj-3258 River Hopscotch
- POJ3258:River Hopscotch
- poj 3258 River Hopscotch
- POJ3258-River Hopscotch
- poj 3258 River Hopscotch
- POJ 3258 River Hopscotch
- HDU 5083/BC 15B Instruction
- hdu5762Teacher Bo+曼哈顿距离
- UVA10098Generating Fast
- CSR1010使用UART进行串口通信
- myeclipse对于struts2编译报Invalid result location value/parameter错误
- River Hopscotch
- 74.The database is running in ARCHIVELOG mode. Examine the initialization parameters and their value
- UVALive 3266Tian Ji -- The Horse Racing
- QQZiFramework笔记:entityTable与erp.public.js使用进阶(查询条件、自定义行显示)
- linux变量 set env export的区别
- Task schedule
- 转义字符,格式控制符,自定义头文件
- handler机制的原理
- mysql如何消除表空间碎片