博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ - 2456 Aggressive cows
阅读量:5064 次
发布时间:2019-06-12

本文共 1661 字,大约阅读时间需要 5 分钟。

Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight line at positions x1,...,xN (0 <= xi <= 1,000,000,000). 
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

* Line 1: Two space-separated integers: N and C 
* Lines 2..N+1: Line i+1 contains an integer stall location, xi

Output

* Line 1: One integer: the largest minimum distance

Sample Input

5 312849

Sample Output

3

Hint

OUTPUT DETAILS: 
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.
1 #include 
2 using namespace std; 3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 long long n,k;18 long long a[110000];19 long long panduan(long long zhi)20 {21 int add=1;22 int kaishi=1,jieshu=1;23 while(1)24 {25 if(a[jieshu]-a[kaishi]
<=n)26 {27 jieshu++;28 }29 else if(a[jieshu]-a[kaishi]>=zhi)30 {31 add++;32 kaishi=jieshu;33 }34 else35 break;36 }37 //cout<
<<"_"<
<
>1;53 if(panduan(mid)>=k)54 kaishi=mid;55 else56 jieshu=mid;57 }58 cout<
<
View Code

 

 

转载于:https://www.cnblogs.com/dulute/p/7966712.html

你可能感兴趣的文章
yii 1.x 添加 rules 验证url数组
查看>>
html+css 布局篇
查看>>
银行排队问题(详解队列)
查看>>
input输入提示历史记录
查看>>
序列化和反序列化(1)---[Serializable]
查看>>
对二维数据进行边界拓展
查看>>
asp.net 验证控件
查看>>
评论列表显示及排序,个人中心显示
查看>>
微软职位内部推荐-Software Engineer II
查看>>
区分Integer.getInteger和Integer.valueOf使用方法
查看>>
MySQL oracle 分页
查看>>
iOS基础-UIKit框架-触摸事件-响应者链条
查看>>
SQL优化
查看>>
利用Highcharts插件制作动态图表
查看>>
用C语言操纵Mysql
查看>>
轻松学MVC4.0–6 MVC的执行流程
查看>>
4.9 Parser Generators
查看>>
[10月18日的脚本] 从Access中导入多个表到Excel
查看>>
centos下安装nginx
查看>>
redis集群如何清理前缀相同的key
查看>>