POJ 2236 Wireless Network

Source: Internet
Author: User

It's a matter of counting and checking.


Test instructions is said to have n computers, each computer can be self-centered connected to the D-meter range of computers.

Give the coordinates of the n computer, for the inquiry operation, the output is connected.


I use adjacency table to store, if two computer coordinates distance less than their radius and, save up, indicating that these two points can be connected.

Use online[] to indicate whether it has been repaired. After the repair, you can use and check the collection merge.

The repair operation enables online and then iterates through the neighboring edges of the point, and if there are online, merge.

Then it is for the query output. In a collection, success.


#include <cstdio> #include <cstring> #include <string> #include <queue> #include <algorithm > #include <queue> #include <map> #include <stack> #include <iostream> #include <list># include<set> #include <cmath> #define INF 0x7fffffff#define eps 1e-6using namespace std;int n;double r;vector <int>g[1001];int fa[1001];bool online[1001];struct node{double x, y;} point[1001];int father (int x) {if (x!=fa[ X]) return Fa[x]=father (Fa[x]);}    Double Getlen (node A,node b) {double len=sqrt (POW (a.x-b.x,2) +pow (a.y-b.y,2)); return len-r;}    int main () {scanf ("%d%lf", &n,&r);    for (int i=1; i<=n; i++) scanf ("%lf%lf", &point[i].x,&point[i].y);    for (int i=1; i<=n; i++) fa[i]=i,g[i].clear ();    int cot=0;            for (int i=1, i<=n; i++) for (int j=i+1; j<=n; J + +) {double Len=getlen (point[i],point[j]);     if (len<=0) {g[i].push_back (j);           G[j].push_back (i);    }} memset (Online,0,sizeof (online));    Char str[10];            while (scanf ("%s", str)!=eof) {if (str[0]== ' s ') {int A, B;            scanf ("%d%d", &a,&b);            if (father (a)!=father (b)) puts ("FAIL");        Else puts ("SUCCESS");            } else if (str[0]== ' O ') {int u;            scanf ("%d", &u);            Online[u]=1;                for (int j=0; j<g[u].size (); j + +) {int v=g[u][j];                if (!online[v]) continue;                V=father (v);                if (u==v) continue;            Fa[v]=u; }        }    }}


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.