[ An Ac a Day ^_^ ] [kuangbin带你飞]专题五 并查集 POJ 2236 Wireless Network
题意:
一次地震震坏了所有网点 现在开始修复它们
有N个点 距离为d的网点可以进行通信
O p 代表p点已经修复
S p q 代表询问p q之间是否能够通信
思路:
基础并查集
每次修复一个点重新刷一边图就行了
/* ***********************************************
Author :Sun Yuefeng
Created Time :2016/11/1 15:40:35
File Name :food.cpp
************************************************ */ #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<bitset>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<queue>
#include<list>
#define M(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=1e3+;
const int mod=1e7+;
int dx[]= {,,,-,,-,,-};
int dy[]= {,-,,,-,,,-}; int n,d;
int father[maxn];
bool vis[maxn]; struct network
{
int x,y;
int dis(network a)
{
int xx=a.x-x;
int yy=a.y-y;
return xx*xx+yy*yy;
}
}net[maxn]; bool judge(network a,network b)
{
if(a.dis(b)>d*d) return false;
return true;
} int find(int x)
{
if(father[x]!=x) father[x]=find(father[x]);
return father[x];
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d%d",&n,&d);
for(int i=;i<maxn;i++)
vis[i]=false,father[i]=i;
for(int i=;i<=n;i++)
scanf("%d%d",&net[i].x,&net[i].y);
getchar();
char str[];
int p,q;
while(~scanf("%s",str))
{
if(str[]=='O')
{
scanf("%d",&p);
vis[p]=true;
for(int i=;i<=n;i++)
{
if(i==p||!vis[i]) continue;
if(judge(net[p],net[i]))
{
father[find(p)]=find(i);
}
}
}
else
{
scanf("%d%d",&p,&q);
if(find(p)==find(q)) printf("SUCCESS\n");
else printf("FAIL\n");
}
}
return ;
}
[ An Ac a Day ^_^ ] [kuangbin带你飞]专题五 并查集 POJ 2236 Wireless Network的更多相关文章
- [kuangbin带你飞]专题五 并查集
并查集的介绍可以看下https://www.cnblogs.com/jkzr/p/10290488.html A - Wireless Network POJ - 2236 An earthquake ...
- [kuangbin带你飞]专题五 并查集 A - Wireless Network
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- [ An Ac a Day ^_^ ] [kuangbin带你飞]专题四 最短路练习 POJ 3259 Wormholes
SPFA求负环 模板题 记得每组处理之前clear vector /* *********************************************** Author :Sun Yuef ...
- [kuangbin带你飞]专题四 最短路练习 POJ 3268 Silver Cow Party
题意: 在一个有向图中求n头牛从自己的起点走到x再从x走回来的最远距离 思路一开始是暴力跑dij…… 讲道理不太可能…… 然后就百度了一下 才知道把矩阵转置的话就只需要求两次x的单源最短路…… /* ...
- [kuangbin带你飞]专题四 最短路练习 POJ 1797 Heavy Transportation
求每条道路的最大承载量 和上一道题差不多 就是松弛的规则从最大值变成了最小值 /* *********************************************** Author :Su ...
- [kuangbin带你飞]专题四 最短路练习 POJ 2253 Frogger
求第一个点到第二个点的所有通路上最长的边 dijkstra的变形 每次松弛的是每条边通路上的的最长的边 WA了好几次是因为用了%lf 改成%f就过了…… /* ******************** ...
- [ An Ac a Day ^_^ ] [kuangbin带你飞]专题四 最短路练习 POJ 2387 Til the Cows Come Home
求1到N的最短路 注意有重边 跑一遍dijkstra就行 /* *********************************************** Author :Sun Yuefeng ...
- [kuangbin带你飞]专题1-23题目清单总结
[kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...
- [kuangbin带你飞]专题十一 网络流
ID Origin Title 34 / 81 Problem A POJ 3436 ACM Computer Factory 92 / 195 Problem B POJ 3 ...
随机推荐
- 【July】从头到尾彻底理解KMP
从头到尾彻底理解KMP 作者:July时间:最初写于2011年12月,2014年7月21日晚10点 全部删除重写成此文,随后的半个多月不断反复改进. 1. 引言 本KMP原文最初写于2年多前的2011 ...
- C#中字符转换问题详解
C# 出来也有些日子了,最近由于编程的需要,对 C# 的类型转换做了一些研究,其内容涉及 C# 的装箱/拆箱/别名.数值类型间相互转换.字符的 ASCII 码和 Unicode 码.数值字符串和数值之 ...
- jquery mobile扁平化设计样式--Jquery mobile Flat UI介绍
jquery mobile扁平化设计样式--Jquery mobile Flat UI介绍 这几天开发的web app使用了jquery mobile,jquery mobile自带的样式比较适合做企 ...
- 半同步半异步模式的实现 - MSMQ实现
半同步半异步模式的实现 - MSMQ实现 所谓半同步半异步是指,在某个方法调用中,有些代码行是同步执行方式,有些代码行是异步执行方式,下面我们来举个例子,还是以经典的PlaceOrder来说,哈哈. ...
- Arduino 各种模块篇 粉尘传感器 dust sensor 空气质量检测
Testing a sensor from here. http://www.seeedstudio.com/wiki/Grove_-_Dust_Sensor It's a dust sensor. ...
- the selected server is enabled,but is not configured properly.Deployment to it will not be permitted
用Tomcat添加部署项目的时候报错: the selected server is enabled,but is not configured properly.Deployment to it w ...
- Python pandas 0.19.1 Intro to Data Structures 数据结构介绍 文档翻译
官方文档链接http://pandas.pydata.org/pandas-docs/stable/dsintro.html 数据结构介绍 我们将以一个快速的.非全面的pandas的基础数据结构概述来 ...
- Python中BeautifulSoup中对HTML标签的提取
一开始使用了beautifulSoup的get_text()进行字符串的提取,后来一直提取失败,并提示错误为TypeError: 'NoneType' object is not callable 返 ...
- 开发人员如何上google查资源,如果浏览国外资源方法
启动浏览器后15秒左右,浏览器的右上角就会出现图标 启用防火墙功能(右上角墙形图标),这时候程序就会去寻找网上代理,从而达到访问GOOGLE的效果,提示如果不访问google网站,可再点击一下关闭防火 ...
- OC之类与对象
1.面向过程与面向对象. 1). 完成需求1 将大象放进冰箱. a. 把冰箱门打开. b. 把大象放进去. c. 把冰箱门关上. 这是面向过程的思路. 找1个冰箱,要求这个冰箱可以自己开门,自己把大象 ...