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 ...
随机推荐
- spark Failed to get database default, returning NoSuchObjectException
解决方法:1)Copy winutils.exe from here(https://github.com/steveloughran/winutils/tree/master/hadoop-2.6. ...
- docker基本命令日志
docker run - Run a command in a new container 启动一个新的容器,一般在docker pull之后首次运行此image -i 保持stdout打开 -t 打 ...
- 2.centos7 安装Mesos和marathon
master节点 节点名称 IP地址 master1 192.168.161.128 由于硬件资源有限,这里仅安装一个master节点,会存在单点问题.在实际生产中,尽量不要这样操作. 1.安装zoo ...
- vue.js请求数据(axios)
使用npm安装axios npm install axios --save 在main.js中引入axios import axios from "axios"; 注册axios到 ...
- python连接mysql数据库遇到的问题
1.源代码: from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy ...
- Git简单上传和下载
本文参考 git-简易指南 编写 上传本地代码到gitHub仓库 第一步:建立git仓库 cd到你的本地项目根目录下,执行git命令 git init 第二步:将项目的所有文件添加到仓库中 git a ...
- 用LaTeX画树形结构
用LaTeX画树形结构,比如:文件目录树形图,程序中函数调用关系图等. 找到的一个不错的资源: http://www.texample.net/tikz/examples/feature/trees/ ...
- 关于Ajax的优点与缺点
AJAX (Asynchronous Javascript and XML) 是一种交互式动态web应用开发技术,该技术能提供富用户体验. 完全的AJAX应用给人以桌面应用的感觉.正如其他任何技术,A ...
- Unity Collab
window-services下面打开面板,这里有开关(或者你也可以进入后台项目管理页面删除项目). 最大的圈是项目名称. 然后就打开了下面页面,关上就可以了.
- SVN仓库连同版本信息迁移新服务器的步骤
SVN仓库连同版本信息迁移新服务器的步骤 步骤一:导出(1)链接原服务器,找到SVN Server安装路径下的bin文件,并复制文件路径,如 C:\Program File\SVN Server\bi ...