Problem D 牛栏(aggr)
牛栏(aggr)
Time Limit:10000MS Memory Limit:65536K
Total Submit:129 Accepted:72
Description
FJ新建了一个有N(2 <= N <= 100,000)个畜栏的畜棚.畜栏的位置分布在直线的点x_1, ..., x_N (0 <= x_i <= 1,000,000,000)上.
他的C(2 <= C <= N)只牛不喜欢这个畜棚的设计并且对在同一个畜栏里的其他牛进行攻击。为了防止牛受到伤害,FJ想把这些牛分配到某些畜栏中,使得这些牛所在的任意两个畜栏之间的最短距离尽可能长。求最长的最短距离是多少?
Input
*第1行:两个用空格隔开的整数:N和C
*第2到N+1行:每行包括一个整数,畜栏的位置:X_i
Output
*第一行:一个整数:最长的最短距离
Sample Input
5 3 1 2 8 4 9
Sample Output
3 样例解释: FJ把3只牛放到位置是1、4和8的畜栏里,最短距离是3。
Source
#include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
long long n,a[100010],c;
bool check(int m)
{int start=1,end=2,num=1;while(1){if(start>n||end>n) break;if(a[end]-a[start]>=m) {start=end;end++;num++;}else end++;}return num>=c;
}
int er(int lo,int hi)
{while(lo+1<hi){int mid=(lo+hi)/2;if(check(mid)) lo=mid;else hi=mid;}return lo;
}
int main()
{cin>>n>>c;for(int i=1;i<=n;i++){ scanf("%I64d",&a[i]);}sort(a+1,a+1+n);cout<<er(0,a[n]+1); return 0;
}
Problem D 牛栏(aggr)相关推荐
- linux下yum错误:[Errno 14] problem making ssl connection Trying other mirror.
所有的base 都要取消注释 mirrorlist 加上注释 另外所有的enable都要设为零 目录 今天是要yum命令安装EPEL仓库后 yum install epel-release 突然发现y ...
- A + B Problem
1001: A + B Problem Description 计算 A + B. Input 多组测试数据,每组测试数据占一行,包括2个整数. Output 在一行中输出结果. Sample Inp ...
- Error:(49, 1) A problem occurred evaluating project ':guideview'. Could not read script 'https://r
出现问题如下: Error:(49, 1) A problem occurred evaluating project ':guideview'. > Could not read script ...
- #418 Div2 Problem B An express train to reveries (构造 || 全排列序列特性)
题目链接:http://codeforces.com/contest/814/problem/B 题意 : 有一个给出两个含有 n 个数的序列 a 和 b, 这两个序列和(1~n)的其中一个全排列序列 ...
- ADPRL - 近似动态规划和强化学习 - Note 3 - Stochastic Infinite Horizon Problem
Stochastic Infinite Horizon Problem 3.Stochastic Infinite Horizon Problem 定义3.1 无限范围的马尔可夫决策过程 (Marko ...
- ADPRL - 近似动态规划和强化学习 - Note 2 - Stochastic Finite Horizon Problem
2. Stochastic Finite Horizon Problem 在这一节中主要介绍了随机DP算法来解决不确定性下的有限地范围问题,如Denition 1.4所述,它被表述为一个组合优化问题. ...
- There was a problem confirming the ssl certificate ……
在安装一个Python库onetimepass时发生下面的问题: pip install onetimepass Could not fetch URL https://pypi.python.org ...
- HDU 1757 A Simple Math Problem
Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x & ...
- The C10K problem原文翻译
原文地址:http://www.cnblogs.com/fll/archive/2008/05/17/1201540.html The C10K problem 如今的web服务器需要同时处理一万个以 ...
- This is probably not a problem with npm. There is likely additional logging output above
微信小程序开发交流qq群 173683895 承接微信小程序开发.扫码加微信. E:\weii_objct\invoice-manage-web-view>npm start > ...
最新文章
- dock run mysql v3_docker run mysql成功,但是3306端口不通?
- 用shell脚本监控进程是否存在 不存在则启动的实例
- 人工智能AI、机器学习和深度学习之间的区别是什么?
- android进程与线程详解三:AsyncTask
- Linux 磁盘分区 Fdisk
- vue路由query和params的区别
- 破解技术人才招聘难、培养难!CSDN 软件工程师能力认证标准正式开源开放
- How do you simple use git repository
- 虚拟IP,地址漂移,双机热备
- GBASE数据库安装手册中的一点命令
- iPhone4s/iPad2无shsh降级iOS6.1.3
- YOLOV3训练环境的搭建
- 关于Team Building
- 欺骗的艺术——第二部分(6)
- 天道(遥远的救世主)金句,自悟自性
- The More You Know: Using Knowledge Graphs for Image Classification 论文总结
- 人工智能轨道交通行业周刊-第25期(2022.11.28-12.4)
- torch.utils.data.WeightedRandomSampler样本不均衡情况下带权重随机采样
- python 将JS(JavaScript)的json格式字符串转换为python的字典格式
- 盛大吸金“传奇”不再 陈天桥帝国梦碎