POJ-2456 Aggressive cows---最大化最小值(也就是求最大值)
题目链接:
https://vjudge.net/problem/POJ-2456
题目大意:
有n个牛栏,选m个放进牛,相当于一条线段上有 n 个点,选取 m 个点, 使得相邻点之间的最小距离值最大
解题思路:
二分枚举最小距离的最大值
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int INF = 1e9;
const int maxn = ;
int n, m;
int a[maxn];
bool judge(int x)
{
int last = ;
for(int i = ; i < m; i++)
{
int now = last + ;
while(now <= n && a[now] - a[last] < x)now++;
last = now;
}
return last <= n;
}
int main()
{
cin >> n >> m;
for(int i = ; i <= n; i++)cin >> a[i];
sort(a + , a + n + );
int l = , r = INF + , ans;
while(l <= r)
{
int mid = (l + r) / ;
if(judge(mid))
ans = mid, l = mid + ;
else r = mid - ;
}
cout<<ans<<endl;
return ;
}
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 ( 二分搜索)
题目链接 Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The ...
- 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 (二分)
题目传送门 POJ 2456 Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) s ...
- POJ 2456 Aggressive cows
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11192 Accepted: 5492 ...
- [POJ] 2456 Aggressive cows (二分查找)
题目地址:http://poj.org/problem?id=2456 最大化最小值问题.二分牛之间的间距,然后验证. #include<cstdio> #include<iostr ...
- POJ 2456 Aggressive cows(贪心 + 二分)
原题链接:Aggressive cows 题目大意:农夫 建造了一座很长的畜栏,它包括 个隔间,这些小隔间依次编号为. 但是, 的 头牛们并不喜欢这种布局,而且几头牛放在一个隔间里,他们就要发生争 ...
- [ACM] poj 2456 Aggressive cows (二分查找)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5436 Accepted: 2720 D ...
随机推荐
- Array to List
List<OisDiscountIndex> discountIndexes = Arrays.asList(new OisDiscountIndex[trades.size()]);
- ajax提交文件file 单个文件上传
转载: https://blog.csdn.net/u012867699/article/details/78357401
- thymeleaf总结
thymeleaf 基本功能是将 th:xxx的内容替换html标签的内容 原标签的内容会被替换掉,原内容只是前端用来显示demo的 和freemarker, velocity的重要区别是,它们的自定 ...
- Gone Fishing
原题网址 代码已经写出来了,自己测试的时候没有问题,提交上去之后反馈了我一个Runtime error 一口老血啊! 找了半天还是没找到可能越界啊啥的地方 import java.util.Scan ...
- SQL Server外部链接时报错:Error locating serverInstance specified
SQL Server外部链接时报错:Error locating server/Instance specified 连接时报错信息: 08001 sql server network interfa ...
- ajax 工作原理以及其优缺点
1.什么是AJAX?AJAX全称为“Asynchronous JavaScript and XML”(异步JavaScript和XML),是一种创建交互式网页应用的网页开发技术.它使用:使用XHTML ...
- 转 Python-IndexError: list index out of range
https://www.cnblogs.com/2bjiujiu/p/9063864.html Error:IndexError: list index out of range Where? 对Py ...
- Python3 PIL Image 操作文件后导致占用问题
需求:按图片分辨率范围分类图片(每个商品有N张图片在一个目录内). 实现:用PIL Image打开图片并读取宽度和高度.然后按不同分辨率存档到不同目录. 问题:从原有目录移动到目标目录时出现 “Per ...
- robotframework使用过程中遇到的一些问题
问题1: 在ride上import library,显示红色解决办法:根据菜单栏tools--view ride log提示依次安装缺少的模块,包括natsort.xlrd.xlwd.xlutils, ...
- zabbix--高级篇-监控docker服务(一)
一,配置zabbix 客户端环境 rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix//x86_64/zabbix-release-.el7.noarc ...