"JSOI2010" Group Tribe divided Bzoj 1821

Source: Internet
Author: User

1821: [Jsoi2010]group Tribe Division GroupTime limit:10 Sec Memory limit:64 MB
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. Input

The first line consists of two integers N and K (1<=n<=1000)

Output one row, for optimal partitioning, the distance from the nearest two tribes is exactly two digits after the decimal point. Sample Input5 S
0 0
0 1
1 1
1 0
Sample Output

1.00

Ideas:

To minimize the maximum value, we consider the dichotomy. If we can make the nearest two tribes distance is D, then for a smaller distance than D will certainly be able to complete, so two points.

From each point to the BFS, the distance within the description of the same tribe, to see if there can be more than K tribe, if there are more than K tribe said that the current distance can meet the requirements (merge tribe 22 until only K is left), the distance between the nearest two tribes is certainly greater than D.

1 /**************************************************************2 problem:18213 User:houjikan4 language:c++5 result:accepted6 time:1064 Ms7 memory:1292 KB8 ****************************************************************/9  Ten#include <iostream> One#include <cstring> A#include <string> -#include <cstdio> -#include <cstdlib> the#include <cmath> -#include <algorithm> -#include <queue> -#include <stack> +#include <map> -#include <Set> +#include <list> A#include <vector> at#include <ctime> -#include <functional> - #definePRITNF printf - #defineScafn scanf - #definefor (i,j,k) for (int i= (j); i<= (k);(i) + +) - #defineClear (a) memset (A,0,sizeof (a)) in using namespacestd; -typedefLong LongLL; totypedef unsignedintUint; + Const intinf=0x3fffffff; - //==============struct declaration============== the structpoints{ *   intx, y; $ };Panax Notoginseng //==============var declaration================= - Const intmaxn=1010; the Const Doubleeps=1e-6; + intn,k; A points CLAN[MAXN]; the BOOLVIS[MAXN]; + DoubleLow,high,mid; - //==============function declaration============ $ BOOLCheckDoubleDIS);DoubleDist (points a,points b); $ //==============main code======================= - intMain () - {  the #ifdef file__ -Freopen ("Input.txt","R", stdin);WuyiFreopen ("output.txt","W", stdout); the #endif  -scanf"%d%d",&n,&k); Wu    for(intI=1; i<=n;i++) -scanf"%d%d",&clan[i].x,&clan[i].y); Aboutlow=0, high=1000000000000000.0; $    while(high-low>EPS) { -Mid= (Low+high)/2; -     if(check (mid)) -low=mid; A     Else +High=mid; the   } -printf"%.2lf\n", low); $   return 0; the } the //================fuction code==================== the BOOLCheckDoubledis) the { -   intCnt=0; memset (Vis,false,sizeof(Vis)); in    for(intI=1; i<=n;i++) {//BFS from every location the     if(Vis[i])Continue; theQueue <int> Q; Q.push (i); cnt++; About      while(!P.empty ()) { the       intX=q.front (); Q.pop (); vis[x]=true; the        for(intj=1; j<=n;j++){ the         if(!vis[j]&&dist (clan[j],clan[x]) <=dis) {//distance between two locations <=d, stating in the same tribe + Q.push (j); -vis[j]=true; the         }Bayi       } the     } the   } -   returncnt>=K; - } the DoubleDist (points a,points b) { the   returnsqrt ((Double) (a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y)); the } the 
Bzoj 1821

"JSOI2010" Group Tribe divided Bzoj 1821

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.