River Hopscotch(贪心)
来源:互联网 发布:pb是什么意思网络用语 编辑:程序博客网 时间:2024/05/04 06:09
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<iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>using namespace std;int a[50005];int l,n,m;int b_s(int l,int r){ int mid; while(l<=r) { mid=(l+r)/2; int cnt=0,last=0; for(int i=1; i<=n+1; i++) if(mid>=a[i]-a[last]) cnt++; else last=i; if(cnt>m) r=mid-1; else l=mid+1; } return l;}int main(){ scanf("%d%d%d",&l,&n,&m); a[0]=0; a[n+1]=l; for(int i=1; i<=n; i++) scanf("%d",&a[i]); sort(a,a+n+1); printf("%d\n",b_s(0,l));}
- River Hopscotch(贪心)
- poj 3258 River Hopscotch(二分+贪心)
- POJ 3258-River Hopscotch(二分+贪心)
- POJ-3258-River Hopscotch(二分+贪心)
- 贪心 - poj3258 River Hopscotch
- [POJ](3258)River Hopscotch ---二分查找+贪心(查找+贪心)
- POJ3258 River Hopscotch(二分+贪心)
- POJ 3258 River Hopscotch(贪心+二分查找 最大化最小值)
- poj 3258 River Hopscotch (最小值最大化 二分+贪心)
- poj 3258 River Hopscotch (二分与贪心)
- River Hopscotch(二分)
- River Hopscotch(二分法)
- POJ3258,River Hopscotch,二分加贪心
- 【POJ3258】River Hopscotch 二分答案,贪心check
- [二分+贪心] POJ 3258 River Hopscotch
- POJ3258-River Hopscotch-二分+贪心【最小值最大化】
- poj 3258 River Hopscotch 贪心+二分
- POJ 3258 River Hopscotch(二分+贪心)
- 蓝桥杯 基础练习 十六进制转八进制
- SSH端口转发的理解(精华)
- APP支付之使用ApplePay支付开发步骤
- 未运行Xcode从Git上克隆代码
- 设计模式之适配器模式
- River Hopscotch(贪心)
- Unsupported major.minor version 52.0
- 类的对象和类的指针的区别
- python安装scipy与sklearn模块
- Java——InputStreamReader&OutputStreamWriter字符流实现文本文件复制
- 奇异值分解的几何原理
- Service使用及注意事项
- [UnityUI]UGUI新手引导
- 小心别让圆角成了你列表的帧数杀手