POJ 2236 (and check set)

Source: Internet
Author: User

Test instructions: There are n computers broken, numbered from 1 to N, now to repair the computer and to enable communication between the computer, if the two repaired computer between the direct distance of less than equal to D can communicate, if the distance between computer A and computer C is greater than D but a and C can communicate with Computer B, then A and C can communicate. O A, fix computer A. S a B asks if A and B can communicate.
The puzzle: Every time a computer is repaired, it will go through all the computers and put the repaired and able-to-communicate computer into a set, asking if you can determine whether it is within the set.

#include <stdio.h>#include <math.h>Const intN =1005;structPintx, y;} P[n];intN, Pa[n], vis[n], D;Charstr[5];intCount (p A, p b) {return(a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y);}intGet_parent (intx) {returnx = = Pa[x]? X:PA[X] = get_parent (Pa[x]);}intMain () {scanf("%d%d", &n, &d); for(inti =1; I <= N; i++) {scanf("%d%d", &p[i].x, &AMP;P[I].Y);    Pa[i] = i; } while(scanf('%s ', str)! = EOF) {if(str[0] ==' O ') {intAscanf("%d", &a); Vis[a] =1; for(inti =1; I <= N; i++)if(I! = a && vis[i] && Count (P[a], p[i]) <= d * d) {intpx = Get_parent (a);intPY = get_parent (i);if(px! = py)                        {PA[PX] = py; }                }        }Else{intA, B;scanf("%d%d", &a, &b);if(Get_parent (a) = = Get_parent (b))printf("success\n");Else                printf("Fail\n"); }    }return 0; }

POJ 2236 (and check set)

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.