题目描述 Description
yh拥有一条街道,街道上共有n间房子,每间房子的坐标为xi(yh的房子比较神奇,可能重叠)。
同时,yh有m个女朋友(这是事实),yh打算给每位女朋友分配一间房子。两个女朋友间的距离相隔越近,她们之间产生冲突的可能就越高。yh想尽可能的减小女朋友间的冲突,于是他打算让他的女朋友间的最小距离最大,你能帮yh找出这个最大值吗?
输入描述 Input Description
第一行两个整数,n,m,表示yh有n间房子,有m个女朋友
第二行为n个整数,xi,表示各间房子的坐标。
输出描述 Output Description
输出1行,表示yh女朋友间的最小距离的最大值
样例输入 Sample Input
5 3
1 2 8 4 9
样例输出 Sample Output
3
数据范围及提示 Data Size & Hint
对于30%的数据,n<=100,m<=n,0<=xi<=10000;
对于100%的数据,n<=100000 ,m<=n,0 <= xi <= 1000000000
//codevs2072 ·ÖÅä·¿¼ä ¶þ·Ö
//copyright by ametake
#include
#include
#include
using namespace std;
const int maxn=100000+10;
int a[maxn];
int n,m;
bool can(int x)
{
int cnt=0,last=1;
int i=1;
while (i<=n)
{
while (a[i]-a[last]
=m;
}
int main()
{
freopen("1.txt","r",stdin);
freopen("2.txt","w",stdout);
scanf("%d%d",&n,&m);
int l=1,r=0;
for (int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
sort(a+1,a+n+1);
r=a[n];
while (l
>1; if (can(mid)) { l=mid; } else r=mid-1; } printf("%d\n",l); return 0; }
——天时不如地利,地利不如人和