2018学校暑期集训第三天——几何基础

练习题H  ——   POJ - 2456

Aggressive cows


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 3
1
2
8
4
9

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.


#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;int tree[100010];bool judge(int mid, int n, int m)
{int a = 0;for(int i=1; i<m; i++){int b=a+1;while(b<n && tree[b]-tree[a]<mid)b++;if(b==n)return false;a = b;}return true;
}int main(void)
{int n,m; cin >> n >> m;for(int i=0;i<n;i++)scanf("%d", &tree[i]);sort(tree,tree+n);int min=0,max=99999999;while(max-min>1){int mid=(min+max)/2;if(judge(mid,n,m))min = mid;elsemax = mid;}cout << min << endl; return 0;
}

暑期集训3:几何基础 练习题H: POJ - 2456相关推荐

  1. 暑期集训3:几何基础 练习题C: POJ - 1269

    2018学校暑期集训第三天--几何基础 练习题B --  POJ - 1269 Intersecting Lines We all know that a pair of distinct point ...

  2. 暑期集训3:几何基础 练习题G: HDU - 1052

    2018学校暑期集训第三天--几何基础 练习题G  --   HDU - 1052   (昨天加练题) Tian Ji -- The Horse Racing Here is a famous sto ...

  3. 暑期集训3:几何基础 练习题F:  CodeForces - 1007A ​​​​​​​

    2018学校暑期集训第三天--几何基础 练习题F  --   CodeForces - 1007A Reorder the Array You are given an array of intege ...

  4. 暑期集训3:几何基础 练习题D:  HDU - 2036 ​​​​​​​

    2018学校暑期集训第三天--几何基础 练习题D  --    HDU - 2036 改革春风吹满地 " 改革春风吹满地,  不会AC没关系;  实在不行回老家,  还有一亩三分地.  谢谢 ...

  5. 暑期集训3:几何基础 练习题B: HDU - 2001

    2018学校暑期集训第三天--几何基础 练习题B --  HDU - 2001 计算两点间的距离 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离. Input 输入数据有多组,每组 ...

  6. 暑期集训3:几何基础 练习题A: HDU - 2002

    2018学校暑期集训第三天--几何基础 练习题A  --   HDU - 2002 计算球体积 根据输入的半径值,计算球的体积. Input 输入数据有多组,每组占一行,每行包括一个实数,表示球的半径 ...

  7. 递推(2019暑期集训第一次校赛-H.统计ccsu)

    2019暑期集训第一次校赛-H.统计ccsu 链接:https://ac.nowcoder.com/acm/contest/1068/H 来源:牛客网 题目描述 给一个长度不超过1e5的字符串s,字符 ...

  8. 暑期集训2:ACM基础算法 练习题G:POJ - 1298

    2018学校暑期集训第二天--ACM基础算法 练习题G  --  POJ - 1298 The Hardest Problem Ever Julius Caesar lived in a time o ...

  9. 暑期集训1:C++STL 练习题E:POJ-2431

    2018学校暑期集训第一天--C++与STL 练习题E --  POJ - 2431 E - 二律背反的对偶 A group of cows grabbed a truck and ventured ...

最新文章

  1. 深度学习中的图像分割:方法和应用
  2. xp查看计算机mac地址查询,mac地址查询,教你用dos命令查看mac地址的方法
  3. Visual Studio .Net团队开发[转]
  4. React之组件通信
  5. 说说博客园的“关注”与“网摘”
  6. 2018年1月问答系统综述
  7. 2016网易有道内推笔试题
  8. 知名PS滤镜合集工具Nik Collection 4 for Mac
  9. 中国黑客常用六种工具及防御方法(转)
  10. 清理c盘、c盘哪些文件可以删、图形显示文件大小软件
  11. 店铺流量下跌应该如何解决
  12. js实现京东快递单号查询效果
  13. HTML-定位网页元素
  14. 【XJTU】数学建模
  15. MySQL 表查询关键字
  16. 如何关闭Mybatis的DEBUG log打印
  17. 详解UniSwap、无聊猿、PlatoFarm空投的逻辑
  18. 《数据结构与算法》——树与二叉树之遍历总结
  19. 学术论文写作1——abstract,句型
  20. 关于overflow适配IE的问题

热门文章

  1. EXTJS之Ext.util.Observable自定义事件
  2. MySQL5.5加主键锁读问题
  3. 2012 ARM嵌入式开发应用研讨会杂谈
  4. linux 源码安装浏览器,vps+linux+安装浏览器
  5. 多键开关 android8.0,手机桌面多键开关(SwitchPro Widget )
  6. Oracle数据库联邦,使用联邦数据库将oracle表迁移到DB2(9.7)中的脚本说明
  7. python中opencv中inrange用法_python-opencv中的cv2.inRange函数
  8. STARTUP报错:ORA-00205: error in identifying control file, check alert log for more info
  9. Python培训分享:Python新版本中的6个新特性
  10. JQuery:JQuery 中的CSS()方法