BZOJ1821: [Jsoi2010]group Tribe Division Group

Source: Internet
Author: User

1821: [Jsoi2010]group Tribe Division Group time limit:10 Sec Memory limit:64 MB
submit:1155 solved:557
[Submit] [Status] 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

HINT Source

JSOI2010 Second round Contest1

Exercises

Give you n points, M edge, let you ask for a path, so that s to t the shortest side of the longest

This kind of problem, either MST or dichotomy + judgment

For example:

1.NOIP2013DAY1T3 train transport mst+ multiply on tree

2.CH ROUND-A split rug similar to MST

3.bzoj1614: [Usaco2007 jan]telephone lines Erection Telephone line two points + judgment + similar MST

4.NOI2014DAY1T2 Partial Procedure Enumeration +mst

This model is slightly different, not explicitly given M-edge, but a little conversion can be converted to the above model

What is K-block? K Connected blocks What makes them connected is the edge between 22, because we want to make the edges between the connected block and the connected block as large as possible,

So our smaller side is going to be in the connected block, and we're doing MST, and each new edge is actually equivalent to putting the short side into the connected block.

At the same time, the number of connected blocks-1, when the number of Unicom block only K

At this point the next edge has to be added as the edge between the connected block and the connected block, and the length of this edge is the answer

Code:

1#include <cstdio>2#include <iostream>3#include <cmath>4#include <cstring>5#include <Set>6#include <map>7#include <queue>8#include <vector>9#include <cstdlib>Ten#include <algorithm> One #defineMAXN 1000+10 A #defineMAXM 500000+10 - #defineINF 1000000000 - #defineMoD 1000000 the #defineSQR (x) x*x - using namespacestd; - structedge{intx, y;DoubleW;} E[MAXM]; - intN,K,TOT,FA[MAXN],A[MAXN],B[MAXN]; +InlineintRead () - { +     intx=0, f=1;CharCh=GetChar (); A      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} at      while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} -     returnx*F; - } - BOOLcmp (Edge A,edge B) - { -     returna.w<B.W; in } - intFindintx) {returnfa[x]==x?x:fa[x]=find (Fa[x]);} to intMain () + { -Freopen ("Input.txt","R", stdin); theFreopen ("output.txt","W", stdout); *N=read (); k=read (); $      for(intI=1; i<=n;i++)Panax Notoginseng     { -A[i]=read (); b[i]=read (); the          for(intj=1; j<=i-1; j + +) +          { AE[++TOT].X=J;E[TOT].Y=I;E[TOT].W=SQRT (SQR (ABS (A[I]-A[J)) +SQR (ABS (b[i]-B[j] )); the          } +     } -     //for (int i=1;i<=tot;i++) printf ("%d%d%lf\n", E[I].X,E[I].Y,E[I].W); $     //for (int i=1;i<=n;i++) cout<<a[i]<< ' <<b[i]<<endl; $Sort (e+1, e+tot+1, CMP); -     Doubleans; -      for(intI=1; i<=n;i++) fa[i]=i; the      for(intI=1, j=1; i<=n-k+1; i++) -     {Wuyi       while(Find (e[j].x) ==find (E[J].Y)) J + +; theFa[find (e[j].x)]=find (E[J].Y); -ans=E[J].W;  Wu     } -printf"%.2lf\n", ans); About     return 0; $}
View Code

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.