博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Aggressive cows 二分不仅仅是查找
阅读量:6951 次
发布时间:2019-06-27

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

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7083   Accepted: 3522

Description

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.

Source

 
 
1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 using namespace std;15 const int INF=0x4fffffff;16 const int EXP=1e-6;17 const int MS=100005;18 19 int pos[MS];20 int N,M;21 22 bool judge(int d)23 {24 int last=0;25 int now;26 for(int i=1;i
=N)32 return false;33 last=now;34 }35 return true;36 }37 38 void solve()39 {40 sort(pos,pos+N);41 int l=0,r=INF;42 while(r-l>1) // 注意是区间,很多时候开区间更方便一些。43 {44 int mid=(l+r)/2;45 if(judge(mid))46 l=mid;47 else48 r=mid;49 }50 printf("%d\n",l);51 }52 53 int main()54 {55 while(scanf("%d%d",&N,&M)!=EOF)56 {57 for(int i=0;i

 

转载于:https://www.cnblogs.com/767355675hutaishi/p/4375584.html

你可能感兴趣的文章
【小练习】“表单”制作及答案
查看>>
Android应用程序支持安装到SD卡
查看>>
我的软件工程课目标
查看>>
MYSQL 连接数据库命令收藏
查看>>
C#基础篇六飞行棋
查看>>
汇编语言(王爽)第一章基础知识
查看>>
在创业型软件公司的收获
查看>>
Build SSH for Development on Windows Subsystem for Linux
查看>>
学习:数学----容斥原理
查看>>
WebSite And WebApplication
查看>>
Georgia Tech Online Master of Science in Computer Science 项目经验分享
查看>>
字王珐琅体系列,初稿ok
查看>>
浏览网上资源,了解编译原理就是什么?学习编译原理有什么好处?不学有什么损失?如何学习编译原理?...
查看>>
LeetCode 226. Invert Binary Tree
查看>>
空虚、寂寞、无聊
查看>>
基础学习笔记之opencv(1):opencv中facedetect例子浅析
查看>>
JS中属性/方法调用
查看>>
iOS 7 需要再和 Android 比什么
查看>>
8-Images
查看>>
Python字节码与解释器学习
查看>>