poj 3258River Hopscotch
2016-06-09 11:55
302 查看
题意:一条长l的河,0和l各有一个石头,中间有n个石头,从中间n个石头中去掉m个石头,求所有剩余石头之间距离的最小的最大值
分析:二分
View Code
分析:二分
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; const int maxn=1e5+5; int c[maxn]; int lo,n,m; bool judge(int x){ int t=0,last=0; for(int i=0;i<n;i++) if(c[i]-last>=x){ t++; last=c[i]; if(t==n-m) break; } return (t==(n-m))&&(lo-last>=x); } int main(){ while(~scanf("%d%d%d",&lo,&n,&m)){ for(int i=0;i<n;i++) scanf("%d",c+i); sort(c,c+n); int l=0,r=lo; while(r-l>0){ int mid=l+(r-l+1)/2; if(judge(mid)) l=mid; else r=mid-1; } printf("%d\n",l); } return 0; }
View Code
相关文章推荐
- linux 下wine 和plyaonlinux 安装以及卸载 (linux下运行windows软件的神器)
- zookeeper入门-整理版
- CentOS 7 安装 postgreSQL 9.4
- CentOS 7 安装 postgreSQL 9.4
- IIPP迷你项目(三)“Stopwatch: The Game”
- IEEE802.11数据帧在Linux上的抓取
- vmware下虚拟机centos 桥接上网
- centos 下yum 安装nginx
- 网站常见的安全漏洞
- 搭建Nginx与tomcat整合,用Nginx代替apache
- Linux环境下字符设备驱动开发入门
- actionbar setDisplayOptions用法详解
- CentOS下安装Nginx
- 基础命令
- Web应用架构
- linux 查看软件版本号
- IMF Vmvare 中linux 根分区磁盘扩容 gparted 增加虚拟机磁盘空间
- 安装apacheZeppelin
- Centos下安装GitLab
- find、grep、wc使用方法简单总结