POJ2236

Posted newstartcy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ2236相关的知识,希望对你有一定的参考价值。

//没什么好讲,被卡stringstream了,少用

//并查集
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
const int maxn = 1000 + 25;//节点数目
double dis(double x1,double y1,double x2,double y2)
{
    return sqrt(double((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}//俩点之间距离
bool vis[maxn];//判断节点是否被连通
int father[maxn];
typedef struct
{
    int x,y;
}node;
node arr[maxn];
int find(int node)
{
    if(node!=father[node])
        father[node] = find(father[node]);
    return father[node];
}
int ans[maxn];//以它为顶点的个数
int main()
{
    int n;
    double d;
    while(cin>>n>>d)
    {
        memset(vis,false,sizeof(vis));
        for(int i=1;i<=n;++i)
        {
            father[i] = i;//各自为单独节点
            ans[i] = 1;
        }
        for(int i=1;i<=n;++i)
            scanf("%d%d",&arr[i].x,&arr[i].y);
        //string line;
        char cmd[5];
        while(scanf("%s",cmd)!=EOF)
        {
            int u,v;
            if(cmd[0]==‘O‘)
            {
                scanf("%d",&u);
                for(int i=1;i<=n;++i)
                {
                    if(vis[i]&&i!=u)
                    {
                        double len = dis(arr[u].x,arr[u].y,arr[i].x,arr[i].y);
                        if(len > d)
                            continue;
                        int father1 = find(u);
                        int father2 = find(i);
                        if(father1!=father2/*&&ans1>=ans2*/)
                        {
                            father[father1] = father2;
                        }
                    }
                }
                vis[u] = true;
            }else{
                scanf("%d%d",&u,&v);
                if(find(u)==find(v))
                    cout<<"SUCCESS"<<endl;
                else
                    cout<<"FAIL"<<endl;
            }
        }
    }
}

  

以上是关于POJ2236的主要内容,如果未能解决你的问题,请参考以下文章

POJ-2236(并查集)

poj2236 (并查集)

poj2236Wireless Network

POJ2236

poj2236(并查集)

poj2236(并查集)