二分搜索 POJ 2456 Aggressive cows
/*
二分搜索:搜索安排最近牛的距离不小于d
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
int x[MAXN];
int n, m; bool check(int d) {
int last = ;
for (int i=; i<=m-; ++i) {
int cur = last + ;
while (cur <= n && x[cur] - x[last] < d) cur++;
if (cur == n + ) return false;
last = cur;
}
return true;
} int main(void) { //POJ 2456 Aggressive cows
//freopen ("POJ_2456.in", "r", stdin); while (scanf ("%d%d", &n, &m) == ) {
for (int i=; i<=n; ++i) {
scanf ("%d", &x[i]);
} sort (x+, x++n);
int l = , r = INF;
while (l + < r) {
int mid = (l + r) >> ;
if (check (mid)) l = mid;
else r = mid;
}
printf ("%d\n", l);
} 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 (二分 基础)
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 ...
- [ACM] poj 2456 Aggressive cows (二分查找)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5436 Accepted: 2720 D ...
- POJ 2456 Aggressive cows
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11192 Accepted: 5492 ...
- POJ 2456 Aggressive cows(二分答案)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22674 Accepted: 10636 Des ...
- 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: 25944 Accepted: 11982 ...
- POJ 2456 Aggressive cows(贪心 + 二分)
原题链接:Aggressive cows 题目大意:农夫 建造了一座很长的畜栏,它包括 个隔间,这些小隔间依次编号为. 但是, 的 头牛们并不喜欢这种布局,而且几头牛放在一个隔间里,他们就要发生争 ...
随机推荐
- Sumdiv(poj1845)
题意:求A^B的因子的和. /* 首先将A分解 A=p1^a1*p2^a2*...*pn*an A^B=p1^a1B*p2^a2B*...*pn*anB 因子之和sum=(1+p1+p1^2+...+ ...
- 破损的键盘(codevs 4650)
题目描述 Description 有一天,你需要打一份文件,但是你的键盘坏了,上面的"home"键和"end"键会时不时地按下,而你却毫不知情,甚至你都懒得打开 ...
- 【HDOJ6146】Pokémon GO(DP,计数)
题意:一个2*n的矩阵,从任意一格出发,不重复且不遗漏地走遍所有格子,问方案数 mo 10^9+7 n<=10000 思路:因为OEIS搜出来的两个数列都是错误的,所以考虑DP 设B[i]为2* ...
- 移动端click事件延迟300ms该如何解决
window.addEventListener( "load", function() { FastClick.attach( document.body ); }, fa ...
- P1230 智力大冲浪 洛谷
https://www.luogu.org/problem/show?pid=1230 题目描述 小伟报名参加中央电视台的智力大冲浪节目.本次挑战赛吸引了众多参赛者,主持人为了表彰大家的勇气,先奖励每 ...
- POJ—— 2117 Electricity
Electricity Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5620 Accepted: 1838 Descr ...
- Nginx/Spring:增加上传文件尺寸限制
Nginx: 1. vi /etc/nginx/nginx.config 2. 在server中增加如下行 # set client body size to 20M # client_max_bod ...
- socker地址API
大端字节序是指一个整数的高位字节存储在内存的低地址处,低位字节存储在内存的高地址处.小端字节序是指整数的高位字节存储在内存的高地址处,低位字节则存储在内存的低地址处. 现代pc大多采用小端字节序,故小 ...
- 【转】基于Linux下的TCP编程
http://blog.csdn.net/tigerjibo/article/details/6775534 一.Linux下TCP编程框架 TCP网络编程的流程包含服务器和客户端两种模式.服务器模式 ...
- Port forwarding with xinetd Ask
https://stackoverflow.com/questions/21716673/port-forwarding-with-xinetd --------------------------- ...