• 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;
                }
            }
        }
    }
    

      

    不怕万人阻挡,只怕自己投降。
  • 相关阅读:
    c++运算符重载
    c++ const_cast
    SHL
    C++拷贝构造函数(深拷贝,浅拷贝)
    ps命令详解
    static 修饰符
    “宝洁八大问”整理篇
    linux grep命令
    C++操作符重载
    linux中删除指定日期之前的文件
  • 原文地址:https://www.cnblogs.com/newstartCY/p/11600558.html
Copyright © 2020-2023  润新知