POJ-3258 River Hopscotch 二分枚举求上限
来源:互联网 发布:搞笑视频制作软件 编辑:程序博客网 时间:2024/04/29 12:48
题目链接
题意:有一条河,河的长度已知,河中间有一些石头,石头的数量知道,相邻两块石头之间的距离已知。现在可以移除一些石头,问移除m块石头后,相邻两块石头之间的距离的最小值最大是多少。
思路:二分枚举答案。每 次二分枚举一个值,判断该值能够去掉多少块石头。二分枚举求上限。
#include<stdio.h>#include<iostream>#include<string>#include<string.h>#include<math.h>#include<algorithm>#include<vector>#include<queue>using namespace std;const int maxn = 50005;const int inf = 1<<30;typedef __int64 LL;LL l;int n,m;LL rock[maxn];void fun(){LL ld = 0,rd = l,mid;int counts;while( ld < rd ){mid = (ld+rd)>>1;counts = 0;for( int i = 0,j = 1; j <= n+1; )//找相邻点间最小距离{if( rock[j] - rock[i] <= mid ){j ++; counts ++; //删除rock[j]}else{i = j;j ++;}}if( counts > m )rd = mid;elseld = mid+1;}printf("%d\n",rd);}int main(){//freopen("data.txt","r",stdin);while( scanf("%I64d%d%d",&l,&n,&m) != EOF ){for( int i = 1; i <= n; i ++ )scanf("%I64d",&rock[i]);rock[0] = 0;rock[n+1] = l;sort( rock,rock+n+1 );fun();}return 0;}
0 0
- 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 (二分)
- *Poj 3258 二分 River Hopscotch
- poj 3258 二分 River Hopscotch
- POJ 3258 River Hopscotch (二分)
- POJ 2773 Happy 2006 (公式法 or 二分容斥定理)
- JAVASE_08_@面向对象_多态和Object
- mysql 的小经验
- C++笔试经典题目总结
- 黑马程序员 第二篇:关于继承
- POJ-3258 River Hopscotch 二分枚举求上限
- android平台蓝牙编程
- JAVASE_09天_@面向对象_内部类和异常
- Servlet的生命周期小实例
- SGA与共享内存段(OS内核参数shmmax)
- 补间动画Tween
- JAVASE_11_%多线程_创建和安全问题
- [黑马程序员]第十二篇:Jdbc连接数据库操作
- 薪水