zoukankan      html  css  js  c++  java
  • A

     1 #include <cstdio>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <iostream>
     5 using namespace std;
     6 int par[1005];
     7 bool b[1005];//判断哪个电脑被修好了
     8 struct 
     9 {
    10     int x,y;
    11 }a[1005];
    12 void init(int n)
    13 {
    14     for(int i=1;i<=n;i++)
    15     {
    16         par[i]=i;
    17     }
    18 }
    19 int find(int x)
    20 {
    21     if(par[x]==x)
    22     {
    23         return x;
    24     }
    25     else
    26     {
    27         return par[x]=find(par[x]);
    28     }
    29 }
    30 void unite(int x,int y)
    31 {
    32     x=find(x);
    33     y=find(y);
    34     if(x!=y)
    35         par[x]=y;
    36     else 
    37         return ;
    38 }
    39 bool same(int x,int y)
    40 {
    41     return find(x)==find(y);
    42 }
    43 int main (void)
    44 {
    45     memset(b,false,sizeof(b));
    46     int num;int maxx;
    47     cin>>num>>maxx;
    48     init(num);
    49     for(int i=1;i<=num;i++)
    50     {
    51         scanf("%d %d",&a[i].x,&a[i].y);
    52     }
    53     char op;
    54     int id;
    55     while(~scanf(" %c",&op))
    56     {
    57         if(op=='O')
    58         {
    59             scanf("%d",&id);
    60             b[id]=true;
    61 
    62             for(int i=1;i<=num;i++)
    63             {
    64                 if(b[i]==true)
    65                 {   
    66                     int di=(a[id].x-a[i].x)*(a[id].x-a[i].x)+
    67                         (a[id].y-a[i].y)*(a[id].y-a[i].y);
    68                     if(di<=maxx*maxx)//如果比限制距离小,可以合并
    69                     {
    70                         unite(id,i);
    71                     }
    72                 }
    73             }
    74         }
    75         if(op=='S')
    76         {
    77             int c,d;
    78             scanf("%d %d",&c,&d);
    79             if(find(d)==find(c))
    80                 printf("SUCCESS
    ");
    81             else
    82                 printf("FAIL
    ");
    83         }
    84     }
    85     return 0;
    86 }
  • 相关阅读:
    Leetcode 191.位1的个数 By Python
    反向传播的推导
    Leetcode 268.缺失数字 By Python
    Leetcode 326.3的幂 By Python
    Leetcode 28.实现strStr() By Python
    Leetcode 7.反转整数 By Python
    Leetcode 125.验证回文串 By Python
    Leetcode 1.两数之和 By Python
    Hdoj 1008.Elevator 题解
    TZOJ 车辆拥挤相互往里走
  • 原文地址:https://www.cnblogs.com/ouyang_wsgwz/p/9387898.html
Copyright © 2011-2022 走看看