解题思路:简单并查集,注意时间限制是10000MS,每次进行O操作之后,

      进行一次for循环,进行相关调整。同时注意输入输出格式,见代码:

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = ;
int father[maxn], vis[maxn]; struct node{
double x, y; //此处用double
}p[maxn]; int Find(int x)
{
return father[x] == x ? x : father[x] = Find(father[x]);
} void Union(int x, int y)
{
int rootx = Find(x), rooty = Find(y);
if(rootx != rooty) father[rootx] = rooty;
return ;
} int main()
{
int n, d, k, a, b;
char ch;
scanf("%d %d", &n, &d);
memset(vis, , sizeof(vis));
for(int i = ; i <= n; i++) father[i] = i;
for(int i = ; i <= n; i++) scanf("%lf %lf", &p[i].x, &p[i].y);
while(~scanf(" %c", &ch))
{
if(ch == 'O')
{
scanf("%d", &k);
vis[k] = ;
for(int i = ; i <= n; i++)
{
if(!vis[i]) continue; //必须是已经修过的
//两点距离小于等于d,则可以合并
if(sqrt((p[i].x-p[k].x)*(p[i].x-p[k].x)+(p[i].y-p[k].y)*(p[i].y-p[k].y)) <= d)
Union(i, k);
}
}
else
{
scanf("%d %d", &a, &b);
//根节点相同,则表明可以连接
if(Find(a) == Find(b)) printf("SUCCESS\n");
else printf("FAIL\n");
}
}
return ;
}

POJ2236 Wireless Network的更多相关文章

  1. POJ2236 Wireless Network 并查集简单应用

    Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...

  2. POJ-2236 Wireless Network 顺便讨论时间超限问题

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 26131   Accepted: 108 ...

  3. poj-2236 Wireless Network &&poj-1611 The Suspects && poj-2524 Ubiquitous Religions (基础并查集)

    http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由 ...

  4. POJ2236 Wireless Network 并查集

    水题 #include<cstdio> #include<cstring> #include<queue> #include<set> #include ...

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

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

  6. POJ2236:Wireless Network(并查集)

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

  7. D - Wireless Network

    来源poj2236 An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have s ...

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

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

  9. [并查集] POJ 2236 Wireless Network

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 25022   Accepted: 103 ...

随机推荐

  1. 简约的单页应用引擎:sonnyJS

    点这里 SonnyJS是一个简约的单页应用引擎和HTML预处理器,旨在帮助开发人员和设计人员创建难以置信的强大和快速的单页网站. 主要特性: 模板嵌套,模板继承 动态同步模板路由(非Ajax) 跨窗口 ...

  2. android 启动adb

    1.命令行进入 sdk/platform-tools 2.执行命令 adb kill-server 3.执行命令 adb start-server

  3. hdu 3404 Switch lights 博弈论

    主要是求NIM积!!! 代码如下: #include<iostream> #include<cstdio> #include<stack> #include< ...

  4. JAVA类型信息——反射机制

    JAVA类型信息——反射机制 一.反射机制概述 1.反射机制:就是java语言在运行时拥有的一项自我观察的能力,java通过这种能力彻底了解程序自身的情况,并为下一步的动作做准备. 2.反射机制的功能 ...

  5. Spark源码分析(二)-SparkContext创建

    原创文章,转载请注明: 转载自http://www.cnblogs.com/tovin/p/3872785.html  SparkContext是应用启动时创建的Spark上下文对象,是一个重要的入口 ...

  6. el中保留字empty与null的区别

    先看例子: <%@page pageEncoding="utf-8" %><BR>name:${param.name }<br /> empty ...

  7. 简单Ajax例子

    一.概述 1.程序执行流程: (1)点击id="testBtn"的按钮,触发validate(); (2)validate()中有调用request.open方法与server交互 ...

  8. ajax:serialize() 获取表单集合

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. DB2时间操作

    以下内容选编自<DB2 基础: 日期和时间的使用> 1.使用SQL获取数据库服务器当前时间戳 SELECT current date FROM sysibm.sysdummy1 SELEC ...

  10. linux系统识别和挂载文件系统

    1. 使用df 命令查看文件系统及相关挂载点信息 [root@server101 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on ...