POJ-2236 Wireless Network 顺便讨论时间超限问题
Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 26131 | Accepted: 10880 |
Description
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
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
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
Source

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
struct node
{
int x,y;
int pre;
} p[];
int flag[];
int n,d;
int findn(int x)
{
return x == p[x].pre ? x : findn(p[x].pre);//注意一定要这样写,如果改成普通的while(x!=p[x].pre)就会时间超限!!!以后可以这样简写!
}
void join(struct node p1,struct node p2)
{
int fx=findn(p1.pre),fy=findn(p2.pre);
if(fx!=fy)
if((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)<=d*d)//判断是否符合加入集合的条件
p[fy].pre = fx;
}
int main()
{
scanf("%d %d",&n,&d);
for(int i=; i<=n; i++)
p[i].pre = i;
memset(flag,,sizeof(flag));
for(int i=; i<=n; i++)
scanf("%d %d",&p[i].x,&p[i].y);
char c;
while(scanf("\n%c",&c)!=EOF)//scanf里面的\n用来吸收上一个scanf产生的空行
{
if(c=='O')
{
int a;
scanf("%d",&a);
flag[a] = ;
for(int i=; i<=n; i++)
{
if(flag[i]&&a!=i)//除i自己外其他点均与他建立关系,至于加不加入集合在join里面判断
join(p[i],p[a]);
}
}
else
{
int a,b;
scanf("%d %d",&a,&b);
if(findn(a)==findn(b))
printf("SUCCESS\n");
else printf("FAIL\n");
}
}
return ;
}
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: 16065 Accepted: 677 ...
- [并查集] 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: 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 判断两台计算机是否联通 ...
随机推荐
- 整理用Java实现数字转化成字符串左边自动补零方法
Java 中给数字左边补0 (1)方法一 import java.text.NumberFormat; public class NumberFormatTest { public static vo ...
- 监控LVS
监控LVS #!/usr/bin/python-2.6.6 #data 2017-10-17 #auth liuchao import commands,os,time #-------------- ...
- 深入理解JVM-类加载器深入解析(1)
类加载 在java代码中,类型的加载,连接与初始化过程都是在程序运行期间完成的 类型:表示的Object本身,并不是指一个对象,也就是class. 运行期间:表示的是一种runtime的概念,在运行期 ...
- scripts may close only the windows that were opened by it 浏览器JS控制无法关闭当前页面
非window.open形式打开的子页面用js的window.close在chrome下就会提示scripts may close only the windows that were opened ...
- k8s学习02-----kubeadm部署k8s
机器规划 系统配置 三台机器都执行 1.关闭selinux及firewalld sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux ...
- LR(1)语法分析器生成器(生成Action表和Goto表)java实现(一)
序言 : 在看过<自己实现编译器链接器>源码之后,最近在看<编译器设计>,但感觉伪代码还是有点太浮空.没有掌握的感觉,也因为内网几乎没有LR(1)语法分析器生成器的内容,于是我 ...
- 微信分享(移动web端)
create-at 2019-02-16 引入微信JS-SDK http://res.wx.qq.com/open/js/jweixin-1.4.0.js (当前最新版本) js 相关代码 (移动端实 ...
- android ——通知管理
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle saved ...
- Jenkins持续集成项目搭建——基于Python Selenium自动化测试
参考链接:https://www.liaoxuefeng.com/article/1083282007018592 第一步:去官网https://jenkins.io/下载最新的war包 第二步:安装 ...
- Node.js中的自定义模块化
打造步骤: 1. 创建模块 [ Function / Object / String 2. 导出模块 - module.exports = 模块名称 导出一个 - module.exports = ...