[POJ] 2456 Aggressive cows (二分查找)
题目地址:http://poj.org/problem?id=2456
最大化最小值问题。二分牛之间的间距,然后验证。
#include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdbool.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
#define clr(x,y) memset(x,y,sizeof(x))
#define sqr(x) ((x)*(x))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define LL long long
#define INF 0x3f3f3f3f
#define A first
#define B second
const int N=+;
int n,m,
a[N]; bool check(int d)
{
int last=;
for(int i=;i<m;i++) {
int crt=last+;
while(crt<n && a[crt]-a[last]<d) {
crt++;
}
if(crt==n) return false;
last=crt;
}
return true;
} void solve()
{
sort(a,a+n);
int lb=,ub=INF; while(ub-lb>) {
int mid=(lb+ub)/;
if(check(mid)) {
lb=mid;
} else {
ub=mid;
}
}
printf("%d\n",lb);
} int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<n;i++) {
scanf("%d",&a[i]);
}
solve(); return ;
}
[POJ] 2456 Aggressive cows (二分查找)的更多相关文章
- POJ 2456 Aggressive cows (二分 基础)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7924 Accepted: 3959 D ...
- 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: 22674 Accepted: 10636 Des ...
- poj 2456 Aggressive cows 二分 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=2456 解法 使用二分逐个尝试间隔距离 能否满足要求 检验是否满足要求的函数 使用的思想是贪心 第一个点放一头牛 后面大于等于尝试的距离才放 ...
- [poj 2456] Aggressive cows 二分
Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stal ...
- POJ 2456 Aggressive cows ( 二分 && 贪心 )
题意 : 农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x1,...,xN (0 <= xi <= 1e9) ...
- 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 Agressive cows(二分)
POJ 2456 Agressive cows 农夫 John 建造了一座很长的畜栏,它包括N (2≤N≤100,000)个隔间,这 些小隔间的位置为x0,...,xN-1 (0≤xi≤1,000,0 ...
随机推荐
- lpc1788控制步进电机28BYJ-48
下面直接上代码: #include "lpc177x_8x.h" #include "lpc177x_8x_clkpwr.h" #include "l ...
- 【Xamarin-IOS 开发环境搭建】
MAC 比较贵,虚拟机的干活..... 配置完虚拟机.进去后 ,安装XCode的 时候 ,失败了.错误信息: But when i have tried to install the Xcode it ...
- emacs vim IDE
原本想花点时间来学习下Vim或者emacs,结果在网上搜索到这篇文章 骂战挺多的,但是也长见识 http://bbs.csdn.net/topics/390306165 下面是windows下的ema ...
- 完美:adobe premiere cs6破解版下载[序列号+汉化包+破解补丁+破解教程]
原文地址:http://blog.sina.com.cn/s/blog_6306f2c60102f5ub.html 完美:adobe premiere cs6破解版下载,含序列号.汉化包.注册机.破解 ...
- Java高级软件工程师面试考纲
如果要应聘高级开发工程师职务,仅仅懂得Java的基础知识是远远不够的,还必须懂得常用数据结构.算法.网络.操作系统等知识.因此本文不会讲解具体的技术,笔者综合自己应聘各大公司的经历,整理了一份大公司对 ...
- 程序员必备基础知识:通信协议——Http、TCP、UDP
CP HTTP UDP: 都是通信协议,也就是通信时所遵守的规则,只有双方按照这个规则“说话”,对方才能理解或为之服务. TCP HTTP UDP三者的关系: TCP/IP是个协议组,可分为四个层次: ...
- 利用Excel批量高速发送电子邮件
利用Excel批量高速发送电子邮件,分两步: 1. 准备待发送的数据: a.) 打开Excel,新建Book1.xlsx b.) 填入以下的内容, 第一列:接收人,第二列:邮件标题,第三列:正文,第四 ...
- Could not load the Tomcat server configuration at /Servers/Tomcat v7.0 Server at localhost-config.
[问题] Eclipse[Ubuntu14.04]中启动Tomcat Server[7.0.55]的时候出现错误例如以下: [解决方法] 1.将下边的Servers中的server[Tomcat v7 ...
- TTB 基本
中文名 ,线程构建模块 外文名 Thread Building Blocks 缩 写 TBB 开 发 intel 目录 1线程构建模块 2黑体亮温 3斜交载重轮胎 4串联球轴承 1 ...
- css3标签
-moz代表firefox浏览器私有属性 -ms代表ie浏览器私有属性 -webkit代表chrome.safari私有属性 -o代表opera私有属性 border-radius:2em; 向div ...