POJ-2236 Wireless Network (and collection)

Source: Internet
Author: User

https://cn.vjudge.net/problem/POJ-2236

Test instructions

There is a computer network all the lines are broken, the network has n computers, now you can do two operations, repair (O) and detect whether two computers connected (S), only repaired computer can connect. There is a rule that the distance between two computers cannot exceed a given maximum distance of D (the coordinates of the computer will be given to you at the beginning). Detects when the output two computers can be connected.

Analysis

Note examining. Only repaired can be counted as unicom. So all the repairs were done together.

#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<algorithm>#include<cmath>#include<ctime>#include<vector>#include<queue>#include<map>#include<stack>#include<Set>#include<bitset>using namespaceStd;typedefLong Longll;typedef unsignedLong Longull;#defineMS (A, b) memset (A, B, sizeof (a))#definePB Push_back#defineMP Make_pair#definePII Pair<int, int>#defineEPS 0.0000000001#defineIOS ios::sync_with_stdio (0); Cin.tie (0);#defineRandom (A, b) rand () *rand ()% (b-a+1) +a#definePi ACOs (-1)Constll INF =0x3f3f3f3f3f3f3f3fll;Const intINF =0x3f3f3f3f;Const intMAXN = ++ -;Const intMAXM =200000+Ten;Const intMoD =998244353;intFA[MAXN];intN,d;pair<int,int>P[MAXN];BOOLCheck (pair<int,int> x,pair<int,int>y) {    return(X.first-y.first) * (X.first-y.first) + (x.second-y.second) * (X.second-y.second) <=d*D;}intFindintx) {    returnx==fa[x]?x:fa[x]=find (Fa[x]);}voidUnion (intXinty) {    intFx=find (x), fy=find (y); if(fx!=fy) fa[fx]=fy;}intTMP[MAXN];intMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);//freopen ("Output.txt", "w", stdout);#endifscanf ("%d%d",&n,&d);  for(intI=1; i<=n;i++) scanf ("%d%d", &p[i].first,&p[i].second), fa[i]=i; Charop[3]; intx, y; intCnt=0;  while(~SCANF ("%s", op)) {        if(op[0]=='O') {scanf ("%d",&x);  for(intI=0; i<cnt;i++){                if(tmp[i]!=x&&check (p[tmp[i]],p[x]))                {Union (tmp[i],x); }} tmp[cnt++]=x; }Else{scanf ("%d%d",&x,&y); intFx=find (x), fy=find (y); if(Fx!=fy) puts ("FAIL"); ElsePuts"SUCCESS"); }    }    return 0;}

POJ-2236 Wireless Network (and collection)

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.