ACM题目————Aggressive cows
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.
#include <iostream>
#include <algorithm> using namespace std;
const long long INF = 1000000002;
int a[100002], C, n; bool OK(int m)
{
int last = 0;
for(int i=1; i<C; i++)
{
int cur = last + 1 ;
while(cur<n && a[cur]-a[last]<m) cur ++ ;
if(cur==n) return false ;
last = cur ;
}
return true;
} int main()
{
cin >> n >> C ;
for(int i=0; i<n; i++) cin >> a[i] ;
sort(a,a+n);//排序
int low = 0, high = a[n-1] + 1 ;
while(high - low > 1)
{
int mid = (low + high) >> 1 ;
if(OK(mid)) low = mid ;
else high = mid ;
}
cout << low << endl ; return 0;
}
ACM题目————Aggressive cows的更多相关文章
- [ACM] poj 2456 Aggressive cows (二分查找)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5436 Accepted: 2720 D ...
- poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分
poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分 题目链接: nyoj : http://acm.nyist.net/JudgeOnline/ ...
- POJ2456 Aggressive cows 2017-05-11 17:54 38人阅读 评论(0) 收藏
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13993 Accepted: 6775 ...
- 二分算法的应用——最大化最小值 POJ2456 Aggressive cows
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Description Far ...
- 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: 7924 Accepted: 3959 D ...
- 二分搜索 POJ 2456 Aggressive cows
题目传送门 /* 二分搜索:搜索安排最近牛的距离不小于d */ #include <cstdio> #include <algorithm> #include <cmat ...
- 【POJ - 2456】Aggressive cows(二分)
Aggressive cows 直接上中文了 Descriptions 农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x ...
- 二分-F - Aggressive cows
F - Aggressive cows Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. ...
随机推荐
- IIS 相关
Restart IIS: run "iisreset" command check port usage: netstat -ano How to set up SSL in II ...
- js - ajax中的get和post说明
转自:http://www.cnblogs.com/hateyoucode/archive/2009/12/09/1620050.html 一.谈Ajax的Get和Post的区别 Get方式: 用 ...
- java 笔记(4) —— java I/O 流、字节流、字符流
Java中使用流来处理程序的输入和输出操作,流是一个抽象的概念,封装了程序数据于输入输出设备交换的底层细节.JavaIO中又将流分为字节流和字符流,字节流主要用于处理诸如图像,音频视频等二进制格式数据 ...
- UltraEdit常用配置&搭建Java/C开发环境
一:个人使用UE期间总结了以下经常使用的配置 1.手动配置语法高亮 [高级]->[配置]->[编辑器显示]->[语法高亮]->[词语列表的完整路径]->[浏览]找到安装目 ...
- NGINX反向代理
Nginx反向代理 ...
- 刨根问底U3D---关于Delegate的方方面面
我是否需要阅读这篇文章 Code1: private delegate void BloodNumDelegate (); public delegate void ExpNumChangeDeleg ...
- nyist 673 悟空的难题
http://acm.nyist.net/JudgeOnline/problem.php?pid=673 悟空的难题 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 ...
- C++的STL在C#中的应用
这里主要讲几个重要的STL在C#中的应用:vector, map, hash_map, queue, set, stack, list. vector: 在C#中换成了list using Syste ...
- ArrayList和LinkList区别
ArrayList和LinkList区别 前者是数组的数据结构,后者是链表的数据结构 前者应用于排序和查找,后者应用于插入删除
- 夺命雷公狗---node.js---10之POST的接收
首先我们在项目下创建一个表单,代码如下所示: <!DOCTYPE html> <html lang="en"> <head> <meta ...