zoukankan      html  css  js  c++  java
  • 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;
                }
            }
        }
    }
    

      

    不怕万人阻挡,只怕自己投降。
  • 相关阅读:
    linux基础命令笔记
    linux日常常用命令分析
    43.QQ聊天软件GUI窗口编写
    42.线程概念及线程池
    pycham中报:ModuleNotFoundError: No module named 'pymysql'
    python os模块
    python用类的方式创建线程---自创建类
    python server端并发聊天
    python文件上传
    python编码--解码
  • 原文地址:https://www.cnblogs.com/newstartCY/p/11600558.html
Copyright © 2011-2022 走看看