Description

An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are repaired one by one, and the network gradually began to work again. Because of the hardware restricts, each computer can only directly communicate with the computers that are not farther than d meters from it. But every computer can be regarded as the intermediary of the communication between two other computers, that is to say computer A and computer B can communicate if computer A and computer B can communicate directly or there is a computer C that can communicate with both A and B.
In the process of repairing the network, workers can take two kinds of operations at every moment, repairing a computer, or testing if two computers can communicate. Your job is to answer all the testing operations.

Input

The first line contains two integers N and d (1 <= N <= 1001, 0 <= d <= 20000). Here N is the number of computers, which are numbered from 1 to N, and D is the maximum distance two computers can communicate directly. In the next N lines, each contains two integers xi, yi (0 <= xi, yi <= 10000), which is the coordinate of N computers. From the (N+1)-th line to the end of input, there are operations, which are carried out one by one. Each line contains an operation in one of following two formats:
1. "O p" (1 <= p <= N), which means repairing computer p. 2. "S p q" (1 <= p, q <= N), which means testing whether computer p and q can communicate.
The input will not exceed 300000 lines.

Output

For each Testing operation, print "SUCCESS" if the two computers can communicate, or "FAIL" if not.

Sample Input

4 1
0 1
0 2
0 3
0 4
O 1
O 2
O 4
S 1 4
O 3
S 1 4

Sample Output

FAIL
SUCCESS 题目链接:http://poj.org/problem?id=2236

题目要求就是:给你n个坏的计算机 和 限制的连通距离d,然后输入这几台计算机的坐标。
然后输入一个字符O或S,O表示后面输入的 p 这台计算机修好了,S是要你求p和q这两台计算机是否能连通,连通输出SUCCESS否则输出FAIL
现在说明两台计算机能连通的条件:一、这两台计算机的距离要<=d,二、这两台计算机要求都已经修好了 我因为把FAIL写成FALL,wa的我都想哭了,好伤心
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<iostream>
#include<algorithm>
#define N 1100
using namespace std;
struct node
{
int x,y;
};
node a[N];
int d,fa[N],vis[N]; int judge(int x,int y)
{
int d0=(a[x].x-a[y].x)*(a[x].x-a[y].x)+(a[x].y-a[y].y)*(a[x].y-a[y].y);
if(d0<=d*d)
return ;
return ;
} int Find(int x)
{
if(x!=fa[x])
fa[x]=Find(fa[x]);
return fa[x];
}
int main()
{
int n,i,k,x,y;
char str[N];
scanf("%d%d",&n,&d);
for(i=;i<=n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
for(i=;i<=n;i++)
fa[i]=i;
k=;
while(scanf("%s",str)!=EOF)
{
if(strcmp("O",str)==)
{
scanf("%d",&x);
for(i=;i<k;i++)
{
if(judge(x,vis[i])==)//判断两点间的距离是否<=d;
{
int dx=Find(x);
int dy=Find(vis[i]);
if(dx!=dy)
fa[dy]=dx;
}
}
vis[k]=x;
k++;
}
else
{
scanf("%d%d",&x,&y);
if(Find(x)==Find(y))
printf("SUCCESS\n");
else
printf("FAIL\n");
}
}
return ;
}
复习时又写了一遍感觉还可以:
View Co

Wireless Network--poj2236(并查集)的更多相关文章

  1. POJ2236:Wireless Network(并查集)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 39772   Accepted: 164 ...

  2. poj2236 Wireless Network(并查集直接套模板

    题目地址:http://poj.org/problem?id=2236 题目大意:n台电脑都坏了,只有距离小于d且被修好的电脑才可以互相联系,联系可传递.输入n和d,n个点的坐标x y.两个操作:O ...

  3. 【POJ - 2236】Wireless Network (并查集)

    Wireless Network 这接翻译了 Descriptions 地震发生在东南亚.ACM(亚洲合作医疗团队)已经与膝上电脑建立了无线网络,但是一次意外的余震袭击,网络中的所有计算机都被打破了. ...

  4. POJ 2236 Wireless Network(并查集)

    传送门  Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 24513   Accepted ...

  5. poj 2236:Wireless Network(并查集,提高题)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 677 ...

  6. POJ 2236 Wireless Network (并查集)

    Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...

  7. POJ 2236:Wireless Network(并查集)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 36363   Accepted: 150 ...

  8. poj 2236 Wireless Network 【并查集】

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16832   Accepted: 706 ...

  9. Wireless Network(并查集)

    POJ - 2236 #include<iostream> #include<algorithm> #include<cstring> #include<cm ...

  10. POJ3694:Network(并查集+缩点+lca)

    Network Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 13172   Accepted: 4774 题目链接:htt ...

随机推荐

  1. 【代码审计】MIPCMS 远程写入配置文件Getshell

    0x00 环境准备 MIPCMS官网:https://www.mipcms.cn 网站源码版本:MIPCMS内容管理系统 V3.1.0(发布时间:2018-01-01) 程序源码下载:http://w ...

  2. Android studio导入eclipse工程时出现中文全部乱码问题

    File->settings->Copyright的下面File Encoding -> 改成gbk这样修改就OK了

  3. PHP 图片 平均分割

    $filename = 'D://WWW/1.jpg'; $p = 5; // Get new sizes list($width, $height) = getimagesize($filename ...

  4. SQL - 根据天来分组比较

    SELECT COUNT(*) FROM (SELECT WeixinUserID,CONVERT(varchar(100),CreateTime, 23) AS DT FROM SiteVisite ...

  5. 【.netcore学习】.netcore添加到 supervisor 守护进程自启动报错

    配置 supervisor [program:HelloWebApp] command=dotnet run directory=/home/python/dotnet/myweb/mywebapi ...

  6. Delphi应用程序的调试(四)The Debug Inspector

    调试检查器(The Debug Inspector) Debug Inspector使用户能查看诸如类和记录的数据对象,也可以用它来查看整数.字符数组等简单数据类型,但这类简单数据类型最好是用Watc ...

  7. Qt编写密钥生成器+使用demo(开源)

    在很多商业软件中,需要提供一些可以试运行的版本,这样就需要配套密钥机制来控制,纵观大部分的试用版软件,基本上采用以下几种机制来控制.1:远程联网激活,每次启动都联网查看使用时间等,这种方法最完美,缺点 ...

  8. 【Eclipse】Ubuntu 下菜单栏失效了,怎么办?(已解决)

    如果你的 Ubuntu 的版本是 13.10 , 且你又安装了 Eclipse , 你就会发现 Eclipse 的菜单不起作用了. 就是点击 File , Edit ... 这些菜单,不会显示子菜单了 ...

  9. C# 中对COOKIES的操作

    HttpUtility.UrlDecode HttpUtility.UrlEncode HttpContext.Current.Request.Cookies["UserCode" ...

  10. 报错---“node install.js”

    如图 解决方案: 目录中执行 npm install chromedriver --chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromed ...