Bzoj 1821 JSOI2010 Group Tribe Division

Source: Internet
Author: User

1821: [Jsoi2010]group Tribe Division Group time limit:10 Sec Memory limit:64 MB
submit:3064 solved:1449
[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.00make a minimum spanning tree, when the number of Unicom block to K, if the other side, if not the same unicom block, the direct output of this side of the Benquan can be
1#include <bits/stdc++.h>2 #definell Long Long3 using namespacestd;4InlineintRead () {5     intx=0;intf=1;CharCh=GetChar ();6      while(!isdigit (CH)) {if(ch=='-') f=-1; ch=GetChar ();}7      while(IsDigit (CH)) {x=x*Ten+ch-'0'; ch=GetChar ();}8     returnx*F;9 }Ten Const intmaxn=1e6+Ten; One structnode{ A     intx, y; -     Doublev; - }E[MAXN]; the intf[maxn],x[maxn],y[maxn],cnt; -InlineBOOLmycmp (node N,node m) { -     returnn.v<m.v; - } +InlineintFindintx) { -     returnx==f[x]?x:f[x]=find (F[x]); + } A intMain () { at     intN=read ();intm=read (); -      for(intI=1; i<=n;i++){ -f[i]=i; -     } -      for(intI=1; i<=n;i++){ -X[i]=read (); y[i]=read (); in     } -      for(intI=1; i<=n;i++){ to          for(intj=i+1; j<=n;j++){ +             DoubleDIS=SQRT (1.0* (X[i]-x[j]) * (X[i]-x[j]) +1.0* (Y[i]-y[j]) * (y[i]-y[j])); -e[++cnt].x=i;e[cnt].y=j;e[cnt].v=dis; the         } *     } $Sort (e+1, e+cnt+1, mycmp);Panax Notoginseng      for(intI=1; i<=cnt;i++){         -     intFx=find (e[i].x);intfy=find (E[I].Y); the     //cout<<fx<< ' <<fy<<endl; +         if(fx!=FY) { A             if(n>m) { then--;f[fx]=fy; +             } -             Else{ $printf"%.2f\n", E[I].V);return 0; $             } -         } -     } the     return 0; -}
View Code

Bzoj 1821 JSOI2010 Group Tribe Division

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.