poj B

题目链接

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;

const int maxn=1010;

struct node
{
    int x,y;
}N[maxn];

int pre[maxn];
vector<int> V;
int find(int x)
{
    int r=x;
    while(r!=pre[r]){
        r=pre[r];
    }
    int i=x,j;
    while(i!=r){
        j=pre[i];
        pre[i]=r;
        i=j;
    }
    return r;
}
void join(int x,int y)
{
    int fx=find(x),fy=find(y);
    if(fx!=fy)
        pre[fx]=fy;
}

int main()
{
    int n;
    double d;
    cin>>n>>d;
    for(int i=1;i<=n;i++)
        cin>>N[i].x>>N[i].y;
    for(int i=1;i<=n;i++)
        pre[i]=i;
    char ch;
    int x1,x2;
    while(cin>>ch){
        if(ch=='O'){
            cin>>x1;
            int len=V.size();
            for(int i=0;i<len;i++){
                double distance=sqrt((N[V[i]].y-N[x1].y)*(N[V[i]].y-N[x1].y)+(N[V[i]].x-N[x1].x)*(N[V[i]].x-N[x1].x));
                if(distance<=d){
                    join(V[i],x1);
                    /*
                    for(int i=1;i<=n;i++){
                        printf("%d ",pre[i]);
                    }
                    printf("\n");
                    */
                }
            }
            V.push_back(x1);
        }
        else {
            cin>>x1>>x2;
            if(find(x1)==find(x2)){
                cout<<"SUCCESS"<<endl;
            }
            else {
                cout<<"FAIL"<<endl;
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值