poj 2546
来源:互联网 发布:php淘宝互刷平台源码 编辑:程序博客网 时间:2024/05/22 17:51
题意:牛要打架,给出一些房子及他们的位置,问如何放c头牛使得他们之间的最短距离最大。
利用二分法选择最短相距的距离,慢慢逼近最大值。
#include<cstdio>#include<algorithm>using namespace std;const int maxn = 100000 + 5;int pos[maxn], n, c;bool putcows(int space){ int cnt = 1; int last = pos[0]; for(int i = 1; i < n; i++) { if(pos[i] - last >= space) {cnt++; last = pos[i];} if(cnt == c) return true; } return false;}int main(){ while(scanf("%d%d", &n, &c) == 2) { for(int i = 0; i < n; i++) scanf("%d", &pos[i]); sort(pos, pos + n); int L = 0, R = pos[n - 1] - pos[0] + 1; while(R - L > 1) { int mid = (R + L) / 2; if(putcows(mid)) L = mid; else R = mid;//R是非法值 } printf("%d\n", L); } return 0;}
阅读全文
0 0
- poj 2546
- poj 2546 Circular Area
- poj 2546 Circular Area
- POJ 2546 Circular Area
- poj 2546 Circular Area
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- Spring动态切换多数据源解决方案
- FR关于排序名次、分组排序名次问题
- 修改activemq账号密码Linux
- 国外的公司都是如何「处理」大龄程序员的?
- STM32在IAR中调用之printf函数的一个方法
- poj 2546
- 类型错误导致的bug
- Ubuntu16.04安装Hadoop单机和伪分布式环境超详细
- Java 虚拟机
- git添加tag
- pyqt5 使用cv2 显示图片,摄像头
- 创业失败后的他们,是怎么找工作的?
- django配置URL
- 基于JavaMail的Java邮件开发