1821: [Jsoi2010]group Tribe Division Group time limit:10 Sec Memory limit:64 MB
submit:3099 solved:1467
[Submit] [Status] [Discuss] 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 Output1.00
Hintsource
From small to Dalian side, until the formation of K-connected components, the next edge is the answer
Two points can also be done
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <algorithm>6#include <cmath>7#include <queue>8#include <vector>9 #defineMin (A, B) ((a) < (b)? (a): (b))Ten #defineMax (A, B) ((a) > (b)? (a): (b)) One #defineABS (a) ((a) < 0? ( -1 * (a)): (a)) AInlinevoidSwapint&a,int&b) - { - intTMP = A;a = B;b =tmp; the } -InlinevoidReadint&x) - { -x =0;Charch = GetChar (), C =ch; + while(Ch <'0'|| CH >'9') c = ch, ch =GetChar (); - while(Ch <='9'&& CH >='0') x = x *Ten+ CH-'0', ch =GetChar (); + if(c = ='-') x =-x; A } at - Const intINF =0x3f3f3f3f; - Const intMAXN = ++Ten; - - intN, K, tot, CNT[MAXN * MAXN], U[MAXN * MAXN], V[MAXN *MAXN], X[MAXN], Y[MAXN], FA[MAXN]; - intW[MAXN *MAXN]; in - intFindintx) to { + returnx = = Fa[x]? X:FA[X] =find (Fa[x]); - } the * BOOLcmpintAintb) $ {Panax Notoginseng returnW[a] <W[b]; - } the + intMain () A { the read (n), read (k); + for(Registerinti =1; I <= n;++i) -Read (X[i]), read (Y[i]), fa[i] =i; $ for(Registerinti =1; I <= n;++i) $ for(Registerintj = i +1; J <= n;++j) - { -++tot; theU[tot] = i, v[tot] = j, Cnt[tot] =tot; -W[tot] = (X[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j]) * (Y[i]-y[j]);Wuyi } theStd::sort (CNT +1, CNT +1+tot, CMP); - for(Registerinti =1; I <= tot;++i) Wu { - intF1 = Find (U[cnt[i]), F2 =find (V[cnt[i]); About if(f1 = = F2)Continue; $FA[F1] =F2; ---N; - if(n = = k-1) - { Aprintf"%.2LF", sqrt (W[cnt[i] )); + return 0; the } - } $ return 0; the}
BZOJ1821
BZOJ1821: [Jsoi2010]group Tribe Division Group