Advanced C + +--------Set (tribal division)

Source: Internet
Author: User

F.a.qs Home discuss Problemset Status ranklist Contest modifyuser hyxzc Logout Donate this site
Notice:1: Because this OJ is built under Linux platform, and many problems of data under Windows production, please pay attention to input, output statements and data types and scope, to avoid unnecessary re appearance. 2: This site will be launched for beginners of the test system (with the current OJ is separate, non-impact), content covering from the grammar to Noi all the knowledge points, the URL is http://begin.lydsy.com/JudgeOnline/ 1821: [Jsoi2010]group Tribe Division Group time limit:10 Sec Memory limit:64 MB
submit:1678 solved:800
[Submit] [Status] [Discuss] Description Cong study 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 inhabitants of the savage and the number of tribes. The next n rows, each line containing two positive integers x, y, describe the coordinates of a dwelling point (0<= "x," y<= "10000). "<=" "div=" ">output output line, for optimal division, the distance of the nearest two tribes, accurate to two digits after the decimal point. Sample Input4 2
0 0
0 1
1 1
1 0


Sample Output1.00
The following:violent build edges, and then check the set maintenance until n small with kCode:   
1#include <cstdio>2#include <cmath>3#include <iostream>4#include <algorithm>5 #defineMAXN 10106  7 using namespacestd;8  9 intFa[maxn],n,m,cnt=0;Ten   One structSS A    { -      intx; -      inty; the }E[MAXN]; -      - structnode -    { +      intu; -      intv; +      intW; A}s[maxn*MAXN]; at   - intFindintx) -    { -      if(fa[x]==x)returnx; -fa[x]=find (Fa[x]); -      returnFa[x]; in    } -     to BOOLCMP (node A,node b) +    { -      returna.w<B.W; the    } *      $ intMain ()Panax Notoginseng    { -scanf"%d%d",&n,&m);  the       for(intI=1; i<=n;i++) +scanf"%d%d",&e[i].x,&e[i].y); A       for(intI=1; i<=n;i++) the           for(intj=i+1; j<=n;j++)    +             { -cnt=cnt+1;  $s[cnt].u=i; $s[cnt].v=J; -s[cnt].w= (e[j].x-e[i].x) * (e[j].x-e[i].x) + (E[J].Y-E[I].Y) * (e[j].y-e[i].y); -             } theSort (s+1, s+cnt+1, CMP); -     intk=N;Wuyi      for(intI=1; i<=n;i++) fa[i]=i; the      for(intI=1; i<=cnt;i++) -        { Wu          intFa1=find (s[i].u), fa2=find (S[I].V); -          if(FA1!=FA2) k--; Aboutfa[fa1]=FA2; $             if(k<m) {printf ("%0.2lf\n", sqrt (S[I].W));return 0;}  -         }    -}

C + + path advanced--and check set (tribal division)

Related Article

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.