POJ2456 Aggressive cows
二分,关键是转化为二分!
#include <cstdio>
#include <algorithm>
const int maxn = ;
const int maxN = ; int N, C;
int a[maxN];
using namespace std;
bool judge(int x) {
int s = ;
for (int i = ; i < C;i++) {
int ctr = s+;
while (ctr < N && (a[ctr]-a[s] < x)) {
ctr++;
}
if (ctr==N) {
return false;
}
s = ctr;
}
return true;
}
int main(void)
{
scanf("%d%d", &N, &C);
for (int i = ; i < N; i++) {
scanf("%d", &a[i]);
}
sort(a, a+N);
int l = , u = maxn, mid;
for (;(u-l)>;){
mid = (l+u)/;
if (judge(mid)) {
l = mid;
} else {
u = mid;
}
}
printf("%d\n", l);
return ;
}
POJ2456 Aggressive cows的更多相关文章
- 二分法的应用:最大化最小值 POJ2456 Aggressive cows
/* 二分法的应用:最大化最小值 POJ2456 Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...
- POJ2456 Aggressive cows 2017-05-11 17:54 38人阅读 评论(0) 收藏
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13993 Accepted: 6775 ...
- 二分算法的应用——最大化最小值 POJ2456 Aggressive cows
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Description Far ...
- POJ2456 Aggressive cows 二分
Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stal ...
- poj2456 Aggressive cows(二分查找)
https://vjudge.net/problem/POJ-2456 二分,从最大长度开始,不断折半试,如果牛全放下了,就是可行,修改下界,否则改上届. #include<iostream&g ...
- POJ2456 Aggressive cows(二分+贪心)
如果C(d)为满足全部牛之间的距离都不小于d. 先对牛舍的位置排序,然后二分枚举d,寻找满足条件的d. #include<iostream> #include<cstdio> ...
- POJ2456 Aggressive cows(二分)
链接:http://poj.org/problem?id=2456 题意:一个数轴上n个点,每个点一个整数值,有c个奶牛,要放在这些点的某几个上,求怎么放可以使任意两个奶牛间距离的最小值最大,求这个最 ...
- 【POJ - 2456】Aggressive cows(二分)
Aggressive cows 直接上中文了 Descriptions 农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x ...
- [ACM] poj 2456 Aggressive cows (二分查找)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5436 Accepted: 2720 D ...
随机推荐
- Last-Modified,Etag,Expire区别
Last-Modified 是什么 Last-Modified 是 HttpHeader 中的资源的最后修改时间,如果带有 Last-Modified ,下一次发送 Http 请求时,将会发生带 If ...
- 2013级软件工程GitHub账号信息
GitHub账号信息 序号 班级 学号 姓名 个人GitHub网址 1 信1301-1班 20122951 刘伟 https://github.com/weige8882 2 信1301-1班 201 ...
- ROS(Robot Operating System)常用环境变量介绍
本文简单介绍ROS系统中常用的环境变量用途及设置方式.ROS系统环境中除了必须配置的环境变量以外,其他的也是十分有用,通过修改变量路径,可以设置ROS系统中log文件存放路径,单元测试结果存放路径等. ...
- PhoneGap: Android 自定义组件
Hello Core Demo Plugin Development(组件部署): http://docs.phonegap.com/en/2.0.0/guide_plugin-development ...
- Openwrt iptables分析
这里将载有Openwrt的WR841N的路由表dump出来分析一下. 这个是dump出iptables的命令 root@OpenWrt:/etc/config# iptables-save 这里分为4 ...
- Windows数据类型
WORD:16位无符号整形数据 DWORD:32字节无符号整型数据(DWORD32) DWORD64:64字节无符号整型数据 INT:32位有符号整型数据类型 INT_PTR:指向INT数据类型的指针 ...
- 从idea上通过路径去导入项目
这里我用git来演示导入. 首先确定你要导入项目的路径.(我这里用码云路径图片做演示) 1.选择 2.填写
- Jquery 页面首次加载方式
$(document).ready(function(){ alert("111"); }); $(function(){ alert("222"); }); ...
- linux上课
1. service --status-all 2. service sshd restart 3. service --status-all | grep ssh 4. chkconfig --l ...
- e.stopPropagation();与 e.preventDefault();
e.stopPropagation()阻止事件冒泡 <head> <title></title> <script src="Scripts/jque ...