poj-2236-Wireless Network
Wireless Network
| Time Limit: 10000MS | Memory Limit: 65536K | |
| Total Submissions: 24155 | Accepted: 10045 |
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
代码:
#include <iostream>
#include <cstring>
using namespace std;
struct ss
{
int x,y;
}s[1010];
int map[1010][1010];
int vis[1010];
int f[1010];
int find(int n)
{
if(n!=f[n])
f[n]=find(f[n]);
return f[n];
}
int main()
{ int n,d;
cin>>n>>d;
for(int i=1;i<=n;i++)
{
cin>>s[i].x>>s[i].y;
map[i][i]=0;
for(int j=i-1;j>0;j--)
map[i][j]=map[j][i]=(s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y);
}
for(int i=1;i<=n;i++)
f[i]=i;
memset(vis,0,sizeof(vis));
char a[10];
int b,c;
while(cin>>a)
{
if(a[0]=='O')
{
cin>>b;
vis[b]=1;
for(int i=1;i<=n;i++)
{
if(map[b][i]<=d*d&&i!=b&&vis[i])
{
int a1=find(b);
int b1=find(i);
if(a1!=b1);
f[b1]=a1;
}
}
}
else
{
cin>>b>>c;
if(vis[b]&&vis[c]&&find(b)==find(c))
cout<<"SUCCESS"<<endl;
else
cout<<"FAIL"<<endl;
}
} return 0;
}
poj-2236-Wireless Network的更多相关文章
- POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集
POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...
- [并查集] POJ 2236 Wireless Network
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 25022 Accepted: 103 ...
- poj 2236:Wireless Network(并查集,提高题)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 16065 Accepted: 677 ...
- POJ 2236 Wireless Network(并查集)
传送门 Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 24513 Accepted ...
- POJ 2236 Wireless Network (并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 18066 Accepted: 761 ...
- POJ 2236 Wireless Network (并查集)
Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...
- poj 2236 Wireless Network 【并查集】
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 16832 Accepted: 706 ...
- POJ 2236 Wireless Network [并查集+几何坐标 ]
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- poj 2236 Wireless Network (并查集)
链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...
- [ An Ac a Day ^_^ ] [kuangbin带你飞]专题五 并查集 POJ 2236 Wireless Network
题意: 一次地震震坏了所有网点 现在开始修复它们 有N个点 距离为d的网点可以进行通信 O p 代表p点已经修复 S p q 代表询问p q之间是否能够通信 思路: 基础并查集 每次修复一个点重新 ...
随机推荐
- HTML按钮实现!!!文件上传,遮罩层
按钮上传文件: <input type="file" /> file的意思为提交 每个游览器的显示方式都不一样哦 遮罩层: 设两个id <style type ...
- WinMTR
一般在windows 来判断网络连通性用ping 和tracert,ping的话可以来判断丢包率,tracert可以用来跟踪路由. 在Linux中有一个好用的网络连通性判断工具,它可以结合ping n ...
- Atitit atiuse软件系列
Atitit atiuse软件系列 1.1. Atian inputmethod 输入法 方言与多语言多文字支持 (au)1 1.2. File searcher 文件搜索器,支持压缩文件与正则表达 ...
- noip 2016提高组D2T1 problem
我们可以先预处理一下组合数模K的值,然后我们可以发现对于答案ji[n][m],可以发现递推式ji[i][j]=ji[i-1][j]+ji[i][j-1]-ji[i-1][j-1]并对于Cij是否%k等 ...
- wampserver中Apache启动不了的问题
今天晚上安装了wampserver,启动后,右下角的图表橙色,绿色才代表服务启动成功,到底是什么原因导致不能成功启动呢? 网上查资料,说可能是端口冲突,也可能是网络TCP/IP的设置有关系,我设置TC ...
- C# List.ForEach 方法
C#中List.ForEach 方法是对 List 的每个元素执行指定操作. 示例: using System; using System.Collections.Generic; using Sys ...
- C#委托(delegate)
C#中委托(delegate)是一种安全地封装方法的类型,委托是面向对象的.类型安全的. 使用委托的步骤: 1.声明委托 public delegate void DelegateHandler(st ...
- 让Team Foundation Server/TFS自动记住用户名密码解决方案
在使用Team Foundation Server(以下简称TFS) 的时候,在每次打开Visual Studio TFS时候,需要输入用户名和秘密,比较麻烦.现提供一种方法可以解决这个问题: 依次执 ...
- Hadoop官方文档翻译——HDFS Architecture 2.7.3
HDFS Architecture HDFS Architecture(HDFS 架构) Introduction(简介) Assumptions and Goals(假设和目标) Hardware ...
- 批处理:Windows主机通过FTP下载远程Linux主机上文件
问题:在Windows上怎么写个批处理把多个文件FTP依次下载到本地某个目录. 批处理脚本示例: @echo off title Download db files. Don't close it!! ...