Describe
http://www.lydsy.com/JudgeOnline/problem.php?id=1821
The coordinates of n points are given, and the N points are divided into k parts, so that the minimum distance between each part is the largest.
Analysis
Build edges between every two points, and then from small to to sort. To make the smallest distance the largest, the small distance is used inside each part, so the edges begin to merge until they are merged into K-parts.
1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intmaxn= ++5;5 intn,k;6 intF[MAXN];7 structnode{intx, y;} A[MAXN];8 structedge{9 intx,y,w;Ten Edge () {} OneEdgeintXintYintW): X (x), Y (y), W (w) {} A BOOL operator< (ConstEdge &a)Const{returnw<A.W;} -}e[maxn*MAXN]; -InlineintFindintx) {returnx==f[x]?f[x]:f[x]=find (F[x]);} theInlineintDIS (node A,node b) {returnPow (a.x-b.x,2) +pow (A.Y-B.Y,2); } - intMain () { -scanf"%d%d",&n,&k); - for(intI=1; i<=n;i++) f[i]=i; + for(intI=1; i<=n;i++) scanf ("%d%d",&a[i].x,&a[i].y); - intCnt=0; + for(intI=1; i<=n;i++) for(intj=i+1; j<=n;j++) e[++cnt]=Edge (I,j,dis (A[I],A[J)); ASort (e+1, e+cnt+1); at for(intI=1; i<=cnt;i++){ - intFx=find (e[i].x), fy=find (E[I].Y); - if(fx!=FY) { - if(n>k) n--, f[fx]=fy; - Else{ -printf"%.2lf\n", sqrt (E[I].W)); in Break; - } to } + } - return 0; the}
View Code
1821: [Jsoi2010]group Tribe Division Group time limit:10 Sec Memory limit:64 MB
submit:1791 solved:862
[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
JSOI2010 Second round Contest1
Bzoj_1821_[jsoi2010]_ Tribe Division _ (greedy, and search set)