POJ 3258 River Hopscotch 二分
2017-09-10 11:44
381 查看
原题链接
题意:牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离,
现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值。
对最小距离二分
对于每一次二分,设最小距离为m,若两石头i,j 距离不超过m,则移除石头j,否则下次从石头j开始计算距离。
判断移除石头数cnt与M关系进行下次二分。
题意:牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离,
现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值。
对最小距离二分
对于每一次二分,设最小距离为m,若两石头i,j 距离不超过m,则移除石头j,否则下次从石头j开始计算距离。
判断移除石头数cnt与M关系进行下次二分。
#include <iostream> #include <algorithm> using namespace std; const int maxn=5e4+10; int d[maxn]; int main(){ int L,N,M; cin>>L>>N>>M; for(int i=1;i<=N;i++) cin>>d[i]; sort(d+1,d+1+N); d[0]=0,d[N+1]=L; int l=0,r=L; while(l<=r){ int cnt=0,m=(l+r)/2,ll=0; //m: current minimum distance, cnt: total of rocks removed for(int i=1;i<=N+1;i++){ if(d[i]-d[ll]<=m) cnt++; //current distance is less than the minimum distance(m), remove No.i rock else ll=i; //satisfies condition, not remove, in next repeating i-ll=1, means no remove } if(cnt>M) r=m-1; else l=m+1; } cout<<l<<endl; return 0; }
相关文章推荐
- poj-3258-River Hopscotch-二分
- POJ 3258 River Hopscotch<二分>
- River Hopscotch POJ - 3258 (二分求最小值)
- 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 二分查找
- River Hopscotch POJ - 3258 (二分求最小值)
- POJ 3258 River Hopscotch 二分答案
- POJ 3258 River Hopscotch 【二分 + 思维】
- River Hopscotch POJ - 3258 (二分求最小值)
- 【POJ】3258 - River Hopscotch 二分->最大化最小值
- poj 3258 River Hopscotch 二分搜索极值
- River Hopscotch POJ - 3258 (二分求最小值)
- POJ-3258 River Hopscotch 解题报告(二分) 牛跳石头
- POJ 3258:River Hopscotch 二分的好想法
- POJ 3258 River Hopscotch 二分