POJ 3258 River Hopscotch 二分
来源:互联网 发布:python 匿名函数 编辑:程序博客网 时间:2024/06/08 05:11
原题链接
题意:牛要到河对岸,在与河岸垂直的一条线上,河中有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;}
阅读全文
0 0
- 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 3258 River Hopscotch(二分)
- 最小二乘法及其拟合
- Spring学习之——控制反转(IoC)与依赖注入(DI)
- git如何删除已经 add 的文件 (如何撤销已放入缓存区文件的修改)
- 【Android】【TP】TP开发常见问题&分析
- JavaScript中七种函数调用方式及对应 this 的含义
- POJ 3258 River Hopscotch 二分
- centos安装tomcat
- IntelliJ IDEA使用之二—编辑器字体设置
- 14章 高级IO
- Java出错 Error:Could not create the Java Virtual Machine Error:A fatal exception has occurred
- linux Oops
- React Native AsyncStorage本地存储工具类
- Windows/linux powershell 安装install
- 3555: [Ctsc2014]企鹅QQ