POJ 3258 River Hopscotch(二分求最小中的最大)
来源:互联网 发布:gps漂移过滤算法 源码 编辑:程序博客网 时间:2024/06/05 19:47
Sample Input
25 5 2214112117
Sample Output
4
题目大意:在n块石头中删除m块石头(不含起始,和结束的石头),求出题目中的最小距离的最大距离。
思路:二分问题,确定上下界,后进行区间的枚举,注意最后的输出时,要的是不断矿大时的mid值,这样才保证最大。
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<math.h>#define LL long long#define inf 0x3f3f3f3fusing namespace std;int a[50010];int main(){ int n,m,j,k,l; while(~scanf("%d%d%d",&l,&n,&m)) { for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); a[0]=0;//将开始和结束的石头也加上。 a[n+1]=l; int low=0,high=l; int pos,sum; int ans; while(high>=low) { sum=0; int mid=(high+low)>>1; pos=0; for(int i=1;i<=n+1;i++) if(a[i]-a[pos]<mid)//比假设的最小值还小就当删除 sum++; else pos=i; if(sum>m) high=mid-1; else { low=mid+1; ans=mid; } } printf("%d\n",ans); }}
1 0
- POJ 3258 River Hopscotch(二分求最小中的最大)
- POJ 3258 River Hopscotch(二分·最小距离最大)
- POJ 3258 River Hopscotch(二分·最小距离最大)
- POJ 3258- River Hopscotch(二分求最小值最大)
- POJ 3258 River Hopscotch 二分
- POJ 3258 River Hopscotch 二分
- poj-3258-River Hopscotch-二分
- River Hopscotch - POJ 3258 二分
- poj 3258 River Hopscotch 【二分】
- POJ 3258 River Hopscotch (二分)
- POJ 3258 River Hopscotch(二分)
- POJ - 3258 River Hopscotch 二分
- POJ 3258 River Hopscotch (二分)
- poj 3258 River Hopscotch二分
- 【POJ 3258】 River Hopscotch (二分)
- poj 3258 River Hopscotch 【二分】
- POJ 3258 River Hopscotch 二分
- POJ 3258 River Hopscotch (二分)
- Makefile 备忘录
- 配置内核 Makefile:1449: *** mixed implicit and normal rules. Stop.
- Ogre动画加载之节点动画、mesh动画及骨骼动画加载方法
- 求问Bresenham算法(中点圆算法)的一些问题
- C# json 一维数组 和 二维数组的转换
- POJ 3258 River Hopscotch(二分求最小中的最大)
- 风靡职场的十大面试题!
- GPU编程配置
- php 获取今日 昨日 本周 上一周 本月 近三个月的起至时间戳
- 富文本,NSAttributedString 与 coreText
- Install MongoDB on OS X
- [LeetCode 224]Basic Calculator
- RESTEasy hello world example
- php使用curl模拟提交XML