Description
Cong research found that the Desert Island Savage always live a gregarious life, but not the whole island of all savages belong to the same tribe, the wild people always cliques form belong to their own tribe, different tribes are often fighting. It's just that it's all a mystery-Cong doesn't know how the tribe is distributed. But the good news is that Cong got a map of the desert island. The map marks the place where N Savages Live (which can be seen as coordinates on the plane). We know that savages of the same tribe always live nearby. We defined the distance of the two tribes as the distance between the two closest settlements in the tribe. Cong also got a meaningful message-the savages were divided into K-tribes in total! That's a good news. Cong hopes to dig out the details of all the tribes from this information. He was experimenting with an algorithm that could find the distance between two tribes for any one tribe division, and Cong hoped to find a way to divide the tribe so that the nearest two tribes could be kept as far away as possible. For example, the diagram on the left shows a good division, while the right is not. Please program to help Cong solve this problem.
The first line of input contains two integers n and K (1< = n < = 1000,1< K < = n), respectively, representing the number of inhabited sites and the number of tribes of savages. The next n rows, each line containing two positive integers x, y, describe the coordinates of a dwelling point (0 < =x, y < =10000) Output
Output line, for the best division, the nearest two tribes distance, accurate to two digits after the decimal point.
Sample Input4 2
0 0
0 1
1 1
1 0
Sample Output
1.00
This is not a silly (bi-----) question Ovo
Feel I am afraid of this language pills, read a long time to understand test instructions
If the distance is x, then the distance between the two inhabitants is less than X, then the two settlements belong to the same tribe.
After all, the intervals between tribes are not the same, and it's hard to come up with a definite answer
Then we'll determine the answer and then we'll decide.
And because the answer satisfies the monotony, we can determine the answer in two points.
The second look and the collection is made up of several trees.
If ans satisfies there is greater than or equal to k a tree shrinks ans
otherwise expand
1#include <iostream>2#include <cstring>3#include <cstdio>4#include <cmath>5 using namespacestd;6 structnode7 {8 intx, y;9}a[1001];Ten intfather[1001],n,k; One A DoubleDis (intXinty) - { - return(sqrt (a[x].x-a[y].x) * (a[x].x-a[y].x) + (A[X].Y-A[Y].Y) * (a[x].y-( a[y].y) )); the } - - intFind (intx) - { + if(X==father[x])returnFather[x]; -father[x]=Find (father[x]); + returnFather[x]; A } at - voidMerge (intXinty) - { - intfx=Find (x); - intfy=Find (y); -father[fx]=fy; in } - to BOOLCheckDoublelen) + { - for(intI=1; i<=n;++i) thefather[i]=i; * for(intI=1; i<=n-1;++i) $ for(intj=i+1; j<=n;++j)Panax Notoginseng if(I!=j && Dis (i,j) <=len && Find (i)! =Find (j)) - Merge (i,j); the intCnt=0; + for(intI=1; i<=n;++i) A if(father[i]==i) the++CNT; + if(cnt<k) - return false; $ Else $ return true; - } - the intMain () - {Wuyiscanf"%d%d",&n,&k); the for(intI=1; i<=n;++i) -scanf"%d%d",&a[i].x,&a[i].y); Wu - DoubleL=0, r=10000; About while(r-l>=0.0001) $ { - DoubleMid= (L+R)/2; - if(check (mid)) -L=mid; A Else +R=mid; the } -printf"%0.2LF", L); $}
1821. [JSOI2010] Tribe division "and search set + two points"