poj2456
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 24979 | Accepted: 11594 |
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<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=;
int n,k;
int a[maxn];
int check(int x){
int cnt=;
int y=a[];
for(int i=;i<=n;i++)
if(a[i]-y>=x){
cnt++;y=a[i];
if(cnt>=k) return ;
}
return ;
}
int main(){
cin>>n>>k;
for(int i=;i<=n;i++){
cin>>a[i];
}
sort(a+,a++n);
int l=,r=a[n],mid;
while (l<r){
mid=(l+r+)/;
if(check(mid)) l=mid;
else r=mid-;
}
cout<<l<<endl;
return ;
}
poj2456的更多相关文章
- poj2456 Aggressive cows(二分查找)
https://vjudge.net/problem/POJ-2456 二分,从最大长度开始,不断折半试,如果牛全放下了,就是可行,修改下界,否则改上届. #include<iostream&g ...
- POJ2456 Aggressive cows 二分
Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stal ...
- POJ-2456 Aggressive cows---最大化最小值(也就是求最大值)
题目链接: https://vjudge.net/problem/POJ-2456 题目大意: 有n个牛栏,选m个放进牛,相当于一条线段上有 n 个点,选取 m 个点, 使得相邻点之间的最小距离值最大 ...
- 二分法的应用:最大化最小值 POJ2456 Aggressive cows
/* 二分法的应用:最大化最小值 POJ2456 Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...
- POJ2456 Aggressive cows
Aggressive cows 二分,关键是转化为二分! #include <cstdio> #include <algorithm> ; ; int N, C; int a[ ...
- poj2456 二分逼近寻找正确答案
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10078 Accepted: 4988 ...
- POJ3258--River Hopscotch(Binary Search similar to POJ2456)
Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully ...
- poj2456(二分+贪心)
题目链接:http://poj.org/problem?id=2456 题意: 有n个呈线性排列的牲畜堋,给出其坐标,有c头牛,求把两头牛的最短距离的最大值. 思路: 先将坐标排个序.两头牛的最短距离 ...
- 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 ...
随机推荐
- C# - 配置动态更新
生产中经常会遇到修改配置的情况,但是又需要重启应用程序,是不是有点小烦躁.... 下面了解下在不重启情况下,实现配置更新实时生效 public static void SetConfig(string ...
- python编码和解码
一.什么是编码 编码是指信息从一种形式或格式转换为另一种形式或格式的过程. 在计算机中,编码,简而言之,就是将人能够读懂的信息(通常称为明文)转换为计算机能够读懂的信息.众所周知,计算机能够读懂的是高 ...
- 基于CentOS设置和使用Yum软件仓库
参考:How To Set Up and Use Yum Repositories on a CentOS 6 VPS 参考:CentOS yum 源的配置与使用 介绍 Yum仓库是Linux软件仓库 ...
- 论文阅读:Deformable ConvNets v2
论文地址:http://arxiv.org/abs/1811.11168 作者:pprp 时间:2019年5月11日 0. 摘要 DCNv1引入了可变形卷积,能更好的适应目标的几何变换.但是v1可视化 ...
- PAT基础级-钻石段位样卷2-7-6 帅到没朋友 (20 分)
当芸芸众生忙着在朋友圈中发照片的时候,总有一些人因为太帅而没有朋友.本题就要求你找出那些帅到没有朋友的人. 输入格式: 输入第一行给出一个正整数N(≤),是已知朋友圈的个数:随后N行,每行首先给出一个 ...
- Eclipse安装zookeeper监控插件
1.在 Eclipse 菜单打开Help -> Install New Software…2.添加 url http://www.massedynamic.org/eclipse/updates ...
- Docker那些事儿之编排工具docker-compose
前面已经讲解过docker的一些基础使用,镜像创建的操作过程,如果大量容器需要同时部署,一个一个容器进行服务器上的部署,估计要疯掉,在使用上我们需要找到更好更便捷的使用方式,今天要讲解的容器编排工具d ...
- 一份令人愉快的vs代码包和资源的整理清单
https://viatsko.github.io/awesome-vscode/ https://github.com/viatsko/awesome-vscode
- ElementUI 之 DatePicker 日期限制范围 disabledDate
需求: 时间选择器,只能选择 2000 年 - 至今的年份. <el-date-picker v-model="year" type="year" :pi ...
- javascript权威指南第15章 使用Canvas绘图
HTML <!DOCTYPE html> <html> <head> <title>canvas</title> </head> ...