二分搜索 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 题目大意:农夫 建造了一座很长的畜栏,它包括 个隔间,这些小隔间依次编号为. 但是, 的 头牛们并不喜欢这种布局,而且几头牛放在一个隔间里,他们就要发生争 ...
随机推荐
- 【BZOJ2330】糖果(差分约束系统,强连通分量,拓扑排序)
题意: 幼儿园里有N个小朋友,lxhgww老师现在想要给这些小朋友们分配糖果,要求每个小朋友都要分到糖果.但是小朋友们也有嫉妒心,总是会提出一些要求,比如小明不希望小红分到的糖果比他的多,于是在分配糖 ...
- jQuery插件之ajaxFileUpload(ajax文件上传)
一.ajaxFileUpload是一个异步上传文件的jQuery插件. 传一个不知道什么版本的上来,以后不用到处找了. 语法:$.ajaxFileUpload([options]) options参数 ...
- 如何爬取可用的IP代理
上一篇说到对付反爬虫有一个很关键的方法就是使用IP代理,那么我们应该如何获取这些可用的IP代理呢?这里分享一下自己这两天的一些爬取IP代理的心得体会. 1 步骤 1.找到几个提供免费IP代理的网站,获 ...
- HDU——2874 Connections between cities
Connections between cities Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- Java并发包——线程池
Java并发包——线程池 摘要:本文主要学习了Java并发包中的线程池. 部分内容来自以下博客: https://www.cnblogs.com/dolphin0520/p/3932921.html ...
- 模拟用户点击弹出新页面不会被浏览器拦截_javascript技巧
原文:http://www.html5cn.com.cn/article/zxzx/3195.html 相信用过window.open的小伙伴们都遇到过被浏览器拦截导致页面无法弹出的情况:我们换下思路 ...
- DELPHI异步选择模型UDP
unit U_FrmServer; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Di ...
- 【Nginx】epoll及内核源码详解
内核源码: https://www.nowcoder.com/discuss/26226?type=0&order=0&pos=21&page=1 epoll流程: 首先调用e ...
- Hadoop 执行过程中出现 name node is in safe mode 问题
解决方法: 1.进入hadoop安装根目录 如 :我的hadoop 安装在/usr/local/hadoop 执行 cd /usr/local/hadoop bin/hadoop dfsadmin - ...
- ios跟踪工具introspy使用
1.cydia安装introspy,前提要安装Applist (雷锋源) 2.设置中有introspy-Apps instrospy-Settings选项. 可以选择需要跟踪的app以及跟踪内 ...