POJ 2236 Wireless Network (also set)

Source: Internet
Author: User

Test instructions

There are n computers that are damaged, and they are now going to be repaired on a per-station basis, and they will resume communication functions with each other. If two computers can communicate with each other, there are two cases, one is the distance between them is less than D, and the second is that they can access the third repaired computer. Give all the coordinates of the computer, the two possible operations, O X means to repair the X, S x y to determine whether the communication between x y, if you can output success, otherwise output fall.

Ideas:

Use and check sets to keep the computer connected to each other.
Each time the computer is repaired, it communicates with the computer (the distance is satisfied and repaired) to connect with it.

#include <cstdio> #include <cstring> #include <string> #include <iostream> using namespace s td;const int MAXN = + 5;struct node{int x, y;} Pos[maxn];int P[MAXN], vis[maxn];int find (int x) {return p[x] = = x = x:p[x] = find (P[x]);} void Unionset (int x, int y) {int px = find (x), py = Find (y), if (px! = py) p[px] = py;} int main () {int n, d;scanf ("%d%d", &n, &d), memset (Vis, 0, sizeof (VIS)), for (int i = 1; I <= n; ++i) P[i] = I;fo R (int i = 1; I <= n; ++i) scanf ("%d%d", &pos[i].x, &pos[i].y); GetChar (); Char S[20];while (fgets (S, sizeof (s), stdin) = NULL) {Char op;int A, b;if (s[0] = = ' s ') {sscanf (S, "%c%d%d", &op, &a, &b); int rx = Find (a), Ry = Find (b), if (Rx = = ry) printf ("success\n"), Else printf ("fail\n");}  else {sscanf (S, "%c%d", &op, &a); Vis[a] = 1;int x = pos[a].x, y = pos[a].y;for (int i = 1; I <= n; ++i) {if (a = = I | | !vis[i]) Continue;int x1 = pos[i].x, y1 = pos[i].y;if ((x-x1) * (x-x1) + (y-y1) * (y-y1) <= d*d) {Unionset (A, I);}}} 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.