2456 Aggressive cows
Aggressive cows
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 23866 | Accepted: 11141 |
Description
His C (2 <= C <= N) cows don't like this barn layout and become aggressive towards each other once put into a stall. To prevent the cows from hurting each other, FJ want to assign the cows to the stalls, such that the minimum distance between any two of them is as large as possible. What is the largest minimum distance?
Input
* Lines 2..N+1: Line i+1 contains an integer stall location, xi
Output
Sample Input
5 3
1
2
8
4
9
Sample Output
3
Hint
FJ can put his 3 cows in the stalls at positions 1, 4 and 8, resulting in a minimum distance of 3.
Huge input data,scanf is recommended.
尝试了剪枝 结果运行时间并没有什么区别(注释掉的地方是剪枝)
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
const int si = 100010, inf = 1000000000 + 10;
using namespace std;
int N, COW;
int ar[si]; bool c(int dis) {
int pre = 0, finished = 1;
for (int i = 1; i < N && finished < COW; i++) {
//if (ar[N - 1] - ar[pre] < dis * (COW - finished)) return false;
//剪枝 剩下COW - finished头牛 每头牛需要dis的距离
if (ar[i] - ar[pre] >= dis) {
finished++;
pre = i;
}
}
return finished >= COW;
}
int main() {
cin >> N >> COW;
for (int i = 0; i < N; i++) scanf("%d", &ar[i]);;
sort(ar, ar + N);
int l = 1, m, r = inf;
while (l < r - 1) {
m = l + r >> 1;
if (c(m)) l = m;
else r = m;
}
cout << l << endl;
return 0;
}
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 (二分 基础)
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7924 Accepted: 3959 D ...
- [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 题目大意:农夫 建造了一座很长的畜栏,它包括 个隔间,这些小隔间依次编号为. 但是, 的 头牛们并不喜欢这种布局,而且几头牛放在一个隔间里,他们就要发生争 ...
随机推荐
- PID算法(c 语言)(来自老外)
#include <stdio.h> #include<math.h> //定义PID 的结构体 struct _pid { int pv; // integer that c ...
- Html img 标签
Html img 标签 <html> <body> <!-- img 标签用于显示图片.src="xxx.jpg" 指定图片路径名称--> &l ...
- Python 匿名变量
匿名变量的使用 calc = lambda x:x*3 print(calc(3)) 注:匿名变量是没有名字的变量 注:使用:lambda 创建.
- Shell 实践、常用脚本进阶
1.备份单个文件 #!/bin/bash #备份单个文件 DATE=`/bin/date +%y%m%d` /bin/tar -czpf /backup/$1.$DATE.tar.gz /backup ...
- 谷歌技术"三宝"之GFS
题记:初学分布式文件系统,写篇博客加深点印象.GFS的特点是使用一堆廉价的商用计算机支撑大规模数据处理. 虽然"The Google File System " 是03年发表的老文 ...
- kernel: INFO: task sadc:14833 blocked for more than 120 seconds.
早上一到,发现oracle连不上. 到主机上,发现只有oracleora11g一个进程,其他进程全没了. Nov 14 23:33:30 hs-test-10-20-30-15 kernel: INF ...
- shadows
http://blog.51cto.com/11975865/2308030 https://www.jianshu.com/p/247cdbabf389 https://baijiahao.baid ...
- NPOI解决由于excel删除数据导致空行读取问题
1.解决问题思路一:申明判断是否空行变量用于判断是否空行,声明变量数组用于临时非空行数据,最后存于datatable中. /// <summary>读取excel, /// 默认第一行为表 ...
- MyBio小隐本记注册破解
既然开始了,就把这一个系列的都破了算了,这次主角小隐本记MyBio 和WDTP的原理是差不多的,先把软件界面换成e文,然后写了15个记录后提示注册,一样的路子,直接跳过注册窗口的弹出就好了 然后查壳一 ...
- C# HttpWebResponse WebClient 基础连接已经关闭: 发送时发生错误.
https://blog.csdn.net/sun49842566/article/details/82802297 net 4.0 设置: ServicePointManager.SecurityP ...