最大化最小值poj2456Aggressive cows
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 15528 | Accepted: 7440 |
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.
check(d)=可以安排所有的牛的位置使得最近的两头牛的距离都不小于d
求满足check(d)的最大的d的值。
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
int house[maxn];
int n,m;
const int inf=99999999;
bool check(int d)
{
int last=0;
for(int i=1;i<m;i++)
{
int crt=last+1;
while(crt<n&&house[crt]-house[last]<d)
{
crt++;
}
if(crt==n)return false;
last=crt;
}
return true;
}
void solve()
{
sort(house,house+n);
int lb=0,ub=inf;
while(ub-lb>1)
{
int mid=(ub+lb)/2;
if(check(mid))
lb=mid;
else
ub=mid;
}
printf("%d\n",lb);
}
int main()
{
cin>>n>>m;
for(int j=0;j<n;j++)
scanf("%d",&house[j]);
solve();
return 0;
}
最大化最小值poj2456Aggressive cows的更多相关文章
- poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分
poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分 题目链接: nyoj : http://acm.nyist.net/JudgeOnline/ ...
- 二分法的应用:最大化最小值 POJ2456 Aggressive cows
/* 二分法的应用:最大化最小值 POJ2456 Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...
- POJ_2456_Agressive_cows_(二分,最大化最小值)
描述 http://poj.org/problem?id=2456 有n个小屋,线性排列在不同位置,m头牛,每头牛占据一个小屋,求最近的两头牛之间距离的最大值. Aggressive cows Tim ...
- POJ2456(最大化最小值)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10728 Accepted: 5288 ...
- POJ3285 River Hopscotch(最大化最小值之二分查找)
POJ3285 River Hopscotch 此题是大白P142页(即POJ2456)的一个变形题,典型的最大化最小值问题. C(x)表示要求的最小距离为X时,此时需要删除的石子.二分枚举X,直到找 ...
- hihocoder 二分·二分答案【二分搜索,最大化最小值】 (bfs)
题目 这道题做了几个小时了都没有做出来,首先是题意搞了半天都没有弄懂,难道真的是因为我不打游戏所以连题都读不懂了? 反正今天是弄不懂了,过几天再来看看... 题意:一个人从1点出发到T点去打boss, ...
- codeforce 1070 E Getting Deals Done(二分求最大化最小值)
Polycarp has a lot of work to do. Recently he has learned a new time management rule: "if a tas ...
- nyoj-586-疯牛|poj-2456-Aggressive cows
http://acm.nyist.net/JudgeOnline/problem.php?pid=586 http://poj.org/problem?id=2456 解题思路:最大化最小值二分答案即 ...
- 二分算法的应用——最大化最小值 POJ2456 Aggressive cows
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Description Far ...
随机推荐
- Spring Boot Jpa 表名小写转大写
今天在使用SpringBoot整合Hibernate后创建表,表名为小写,而在linux下,mysql的表名是区分大小写的,因此在我的数据表中,就出现了两个一样的表 act_id_user 和 AC ...
- [bzoj1934/2768][Shoi2007]Vote 善意的投票_最小割
Vote 善意的投票 bzoj-1934 Shoi-2007 题目大意:题目链接. 注释:略. 想法: 这是最小割的一个比较基本的模型. 我们将所有当前同意的小朋友连向源点,边权为1.不容易的连向汇点 ...
- 使用HTML5监測站点性能
在这个信息爆炸的互联网时代,越来越多的人缺少了等待的耐心.站点性能对于一个站点来说越来越重要.下面为监控到的站点打开时间对跳出率的影响: 当站点打开时间在0-1秒时,跳出率为12% 当站点打开时间在1 ...
- 记录一次node中台转发表单上传文件到后台过程
首发掘金 记录一次node中台转发表单上传文件到后台过程 本篇跟掘金为同一个作者leung 公司几个项目都是三层架构模式即前台,中台(中间层),后台.前台微信端公众号使用vue框架,后台管理前端使 ...
- org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected be
1.错误描写叙述 八月 14, 2015 3:03:05 下午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn 警告: Request ...
- Ubuntu虚拟机安装遇到的各种坑
配置 13年Macbook Pro 虚拟机环境 Parallels Desktop Linux 版本 Ubuntu 16.04 1.分辨率问题 进入只有一种分辨率 终端输入 sudo xdiagnos ...
- 使用mpxj读取MSPrjoect
import java.util.ArrayList; import java.util.Calendar; import java.util.Hashtable; import java.util. ...
- HDoj-1250-Hat's Fibonacci-大数
Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 【codevs2183】匹配字符串
KMP裸题 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring ...
- HNOI模拟 Day3.22
第一题: 盾盾的打字机 (drdrd) [题目描述] 盾盾有一个非常有意思的打字机,现在盾哥要用这台打字机来打出一段文章. 由于有了上次的经验,盾盾预先准备好了一段模板 A 存在了内存中,并以此为基础 ...