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

本文共 1593 字,大约阅读时间需要 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.

 

 

题解:求解距离最小值可以取到的最大值(最小值的最大化)

AC代码为:

1 #include
2 #include
3 #include
4 5 6 using namespace std; 7 8 9 int main()10 {11 int N,C,left,right,mid;12 13 cin>>N>>C;14 15 int a[100005];16 17 for(int i=0;i
>a[i];20 }21 22 sort(a,a+N);23 24 left=1,right=a[N-1];25 26 while(right>left+1)27 {28 29 mid=(left+right)/2;30 31 int cns=0; 32 33 for(int i=0;i
=C)40 {41 left=mid;42 }43 else44 {45 right=mid;46 }47 48 }49 50 if(left!=right)51 {52 int cns=0;53 54 for(int i=0;i
=C)63 left=right;64 }65 66 printf("%d\n",left);67 68 return 0;69 }
View Code

 

转载于:https://www.cnblogs.com/songorz/p/9386612.html

你可能感兴趣的文章
Visual Studio 2012使用水晶报表Crystal Report
查看>>
你不知道的 页面编码,浏览器选择编码,get,post各种乱码由来
查看>>
SQLSERVER PRINT语句的换行
查看>>
Windows 8.1 应用开发 – 触控操作
查看>>
PowerDesigner创建物理模型
查看>>
使用Git、Git GUI和TortoiseGit
查看>>
vue---canvas实现二维码和图片合成的海报
查看>>
检查项目里是否有IDFA的方法
查看>>
64位系统使用Access 数据库文件的彻底解决方法
查看>>
注释,字符串
查看>>
性能瓶颈
查看>>
cmd 导入数据库
查看>>
Makefile书写注意事项--个人择记(一)
查看>>
文件转码重写到其他文件
查看>>
场景3 Data Management
查看>>
Dubbo入门---搭建一个最简单的Demo框架(转)
查看>>
树结构练习——排序二叉树的中序遍历
查看>>
AC自动机模板
查看>>
python 基本语法
查看>>
Oracle JDBC hang on
查看>>