POJ2236(Wireless Network)
来源:互联网 发布:淘宝抓取图片软件 编辑:程序博客网 时间:2024/06/05 08:05
Wireless Network
Time Limit: 10000MS Memory Limit: 65536KTotal Submissions: 22345 Accepted: 9387
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.
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.
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 10 10 20 30 4O 1O 2O 4S 1 4O 3S 1 4
Sample Output
FAILSUCCESS题意分析:一张图上分布着n台坏了的电脑,并知道它们的坐标。两台修好的电脑如果距离<=d就可以联网,也可以通过其他修好的电脑间接相连。给出操作“O x”表示修好x,给出操作“S x y”,请你判断x和y在此时有没有联网 代码:#include<iostream>#include<cmath>#include<cstring>#include<stdio.h>using namespace std;#define M 1002int date[M];int set[M],pos[M][2];double arc[M][M];int find(int x){ if(x!=date[x]) date[x]=find(date[x]); return date[x];}void setunion(int x,int y){ int a=find(x); int b=find(y); if(a!=b) date[a]=b;}int main(){ int i,j; int N,D; char ch; int p,q; while(scanf("%d%d",&N,&D)!=EOF) { memset(set,0,sizeof(set)); for(i=1;i<=N;i++) date[i]=i; for(i=1;i<=N;i++) scanf("%d%d",&pos[i][0],&pos[i][1]); for(i=1;i<=N;i++) for(j=1;j<=N;j++) arc[i][j]=double(sqrt( double( pow(pos[i][0]-pos[j][0],2) + pow(pos[i][1]-pos[j][1],2) ) )); while(scanf("%s",&ch)!=EOF) { if(ch=='O') { cin>>p; set[p]=1; for(i=1;i<=N;i++) { if(set[i]&&arc[p][i]<=D) setunion(p,i); } } else { scanf("%d%d",&p,&q); if(find(p)==find(q)) printf("SUCCESS\n"); else printf("FAIL\n"); } } } return 0;}
0 0
- POJ2236 Wireless Network
- poj2236 - Wireless Network
- poj2236 Wireless Network
- POJ2236 Wireless Network
- POJ2236 Wireless Network
- poj2236 Wireless Network
- POJ2236---Wireless Network
- POJ2236--Wireless Network
- poj2236 Wireless Network
- poj2236 Wireless Network
- POJ2236-Wireless Network
- POJ2236(Wireless Network)
- POJ2236 Wireless Network
- poj2236 Wireless Network
- POJ2236 Wireless Network
- poj2236 Wireless Network
- poj2236 Wireless Network
- POJ2236——Wireless Network
- Ghost的相关问题
- STM32的项目文件分组
- linux创建桌面图标,和开始菜单栏图标
- ViewPager.getChildAt()为空问题?
- Tomcat-Session共享实现-Redis
- POJ2236(Wireless Network)
- 基于线程池的线程调度管控系统
- 安卓sdk更新代理
- 使用NOSQL的MongoDB时建立索引需要注意的几点建议和Explain优化分析
- hadoop2.x常用端口、定义方法及默认端口、hadoop1.X端口对比
- 通过up、down、enter键实现搜索结果选择功能(模拟搜索引擎)
- 被改错的密码
- 为什么使用Composer?
- wxpython入门级笔记