GDUT_ winter training solution to a problem report _ the topic title I_I personal solution to a problem report
Diary: The next day, more difficult than the first day, to ten at night, only one subject A, half-baked half-baked data structure reflects the structure of buying and learning to learn bfs not A, Orz.
This topic ideas:
1, this problem is not to say I do not know half-half, this dichotomy is the ultimate dichotomy ans were then given meaning: mid is a good sort sequence, a sequence to find the minimum distance ≥mid
2. So we must write a check, the idea is greedy, direct access to enough.
3. For this topic, should be careful to take mid, make a note of:
1 mid = left + (right- left) / 2 than mid = (right + left) / 2 is better, particularly since the risk right + left will burst int a;
2 MID = left + (right-left +. 1) / 2 partial Right, corresponding to the left and right must favor the left, not the right, opposite too. Otherwise, the situation appears Kichiku 34 becomes 24 or 35 of
The Code
( I commented out, are some Kichiku wrong xjb remedy, this is my real level ):
// code block
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <climits>
#include <queue>
#define ULL unsigned long long
using namespace std;
bool check(int k);
int all[100010];
int N,C;
//int ans_MIN;
int main()
{
scanf("%d %d",&N,&C);
for(int time=0;time<N;time++)
{
scanf("%d",&all[time]);
}
sort(all,all+N);
int left=0,right=all[N-1]-all[0]+1;
//ans_MIN=left;
while(left+1<right)
{
/*
if(right-left==1)
{
if(check(left))ans_MIN=left;
if(check(right))ans_MIN=right;
}
*/
int mid=(right+left)/2;
if(check(mid))
{
//ans_MIN=mid;
left=mid;
}
else right=mid;
}
printf("%d\n",left);
return 0;
}
bool check(int k)
{
int num=C-1;
int location=0;
int last=0;
while(++location)
{
if(num==0)return 1;
else if(location==N)return 0;
else if(all[location]-all[last]>=k){last=location;num--;}
}
}