[ 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 ...
随机推荐
- Service Manager 2012
部署Service Manager 2012遇到的2个问题 上周装了个Service Manager 2012学习,以便完善System Center整个解决方案,在部署期间遇到2个问题,花了我不少时 ...
- C#多线程解决界面卡死问题
C#多线程解决界面卡死问题的完美解决方案 文章下最方有源码下载 问题描述:当我们的界面需要在程序运行中不断更新数据时, 当一个textbox的数据需要变化时, 对于这个问题可以先参考下我的另外一个文章 ...
- Linux Wine with *.bat *.exe ( Photoshop and etc.. )
Firtly all you need is to install wine on your computer. Mine is ubuntu 12.04 which is running KDE o ...
- Android 检测是否连接蓝牙耳机
前言 欢迎大家我分享和推荐好用的代码段~~ 声明 欢迎转载,但请保留文章原始出处: CSDN:http://www.csdn.net ...
- ASP.NET网站运行常见错误以及解决方法(持续更新)
一.A potentially dangerous Request.Form value was detected from the client 用户在页面上提交表单到服务器时,服务器会检测到一些潜 ...
- Java基础IO文件拷贝练习题
/** * 编写一个程序,把指定目录下的所有的带.java文件都拷贝到另一个目录中,拷贝成功后,把后缀名是.java的改成.txt. */ 1.我们看到这个题还是用大化小的思想来做 分析:1.拷贝 & ...
- Writing clean code is what you must do in order to call yourself a professional.
Clean Code A Handbook of Agile Software Craftsmanship
- 基于DDD的.NET项目搭建
第一次写博客有点小激动,废话不多说先上图: 01_Client:存放UI相关的项目,比如ASP.NET MVC或者相关的Web Model及View Model项目. 02_Hosting:存放与Se ...
- soa服务治理-dubbo
dubbo官网:http://dubbo.io/Home-zh.htm 学习点: 1. 日志的配置
- git commit
使用 git add 命令将想要快照的内容写入缓存区, 而执行 git commit 将缓存区内容添加到仓库中. Git 为你的每一个提交都记录你的名字与电子邮箱地址,所以第一步需要配置用户名和邮箱地 ...