POJ 2456 Aggressive cows
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 11192 | Accepted: 5492 |
Description
His C (2 <= C <= N) cows don't like this barn layout and become aggressive towards each other once put into a stall. To prevent the cows from hurting each other, FJ want to assign the cows to the stalls, such that the minimum distance between any two of them is as large as possible. What is the largest minimum distance?
Input
* Lines 2..N+1: Line i+1 contains an integer stall location, xi
Output
Sample Input
5 3
1
2
8
4
9
Sample Output
3
Hint
FJ can put his 3 cows in the stalls at positions 1, 4 and 8, resulting in a minimum distance of 3.
Huge input data,scanf is recommended.
Source
#include <cstdio>
#include <algorithm>
using namespace std; const int MAXN = 100000+5;
int a[MAXN];
int n, c; bool ok(int d)
{
int pre = 0;
for(int i = 1; i < c; ++i){
int cur = pre+1;
while(cur < n && a[cur]-a[pre] < d)
++cur;
if(cur == n)
return false;
pre = cur;
}
return true;
} int main()
{
scanf("%d%d", &n, &c);
for(int i = 0; i < n; ++i)
scanf("%d", &a[i]);
sort(a, a+n);
int l = 0, r = 0x7fffffff;
while(r-l > 1){
int mid = (l+r)/2;
if(ok(mid)) l = mid;
else r = mid;
}
printf("%d\n", l);
return 0;
}
POJ 2456 Aggressive cows的更多相关文章
- poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分
poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分 题目链接: nyoj : http://acm.nyist.net/JudgeOnline/ ...
- 二分搜索 POJ 2456 Aggressive cows
题目传送门 /* 二分搜索:搜索安排最近牛的距离不小于d */ #include <cstdio> #include <algorithm> #include <cmat ...
- POJ 2456 Aggressive cows (二分 基础)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7924 Accepted: 3959 D ...
- POJ 2456 Aggressive cows (二分)
题目传送门 POJ 2456 Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) s ...
- [ACM] poj 2456 Aggressive cows (二分查找)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5436 Accepted: 2720 D ...
- POJ 2456 Aggressive cows(二分答案)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22674 Accepted: 10636 Des ...
- POJ - 2456 Aggressive cows 二分 最大化最小值
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18099 Accepted: 8619 ...
- poj 2456 Aggressive cows 贪心+二分
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25944 Accepted: 11982 ...
- POJ 2456 Aggressive cows(贪心 + 二分)
原题链接:Aggressive cows 题目大意:农夫 建造了一座很长的畜栏,它包括 个隔间,这些小隔间依次编号为. 但是, 的 头牛们并不喜欢这种布局,而且几头牛放在一个隔间里,他们就要发生争 ...
随机推荐
- c# 在windows服务中 使用定时器
由于最近做自动执行的程序,开始做windows服务程序, 在windows服务中如何使用定时器的时候一直失效, 以前是直接拖入timer控件,但是不能直接运行,后来在网上找了一段程序,好使了. //开 ...
- Oracle导出空表(从来都没有用过的表)
Oracle11g默认对空表不分配segment,故使用exp导出Oracle11g数据库时,空表不会导出! .设置deferred_segment_creation参数为FALSE后,无论是空表还是 ...
- P1005 采药
P1005 采药 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 NOIP2005复赛普及组第三题 描述 辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的 ...
- 百度和 Google 的搜索技术是一个量级吗?
著作权归作者所有. 商业转载请联系作者获得授权,非商业转载请注明出处. 作者:Kenny Chao 链接:http://www.zhihu.com/question/22447908/answer/2 ...
- JavaWeb项目开发案例精粹-第2章投票系统-002配置文件及公共类
1. <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5&qu ...
- 关于delphi Assigned
1. 根据 Delphi 指令参考手册中 说明: Assigned 函式在参数不为 nil 时传回 True, 表示指针已经指到某个内存地址,这个内存地址可能是一个对象地首地址,也可能在函数或过程中, ...
- Sqlserver数据库分页查询
Sqlserver数据库分页查询一直是Sqlserver的短板,闲来无事,想出几种方法,假设有表ARTICLE,字段ID.YEAR...(其他省略),数据53210条(客户真实数据,量不大),分页查询 ...
- PCL—低层次视觉—点云分割(最小割算法)
1.点云分割的精度 在之前的两个章节里介绍了基于采样一致的点云分割和基于临近搜索的点云分割算法.基于采样一致的点云分割算法显然是意识流的,它只能割出大概的点云(可能是杯子的一部分,但杯把儿肯定没分割出 ...
- 坑爹的Mysql
本想尝试下如何使用Spring来管理Hibernate的事务,当配置好Spring的配置文件后,进行插入数据,结果报错了,错误是: Mysql Field * doesn't have a defau ...
- 转:在MyEclipse下创建Java Web项目 入门(图文并茂)经典教程
本文是一篇在Myeclipse下构建Java Web项目的初级教程.图文并茂,非常详细.所用的Myeclipse版本是7.5. 第一步:新建Web Project,如下图. 第二步,在弹出的窗口填写下 ...