POJ2236 Wireless Network 并查集
2016-05-01 17:40
239 查看
水题
View Code
#include<cstdio> #include<cstring> #include<queue> #include<set> #include<cstdlib> #include<algorithm> #include<vector> #include<cmath> using namespace std; typedef long long LL; typedef pair<int,int>pii; const int N=1e3+5; const int INF=0x3f3f3f3f; pii o ; bool vis ; int fa ; int find(int x){ return fa[x]==x?x:fa[x]=find(fa[x]); } int dis(int i,int j){ return (o[i].first-o[j].first)*(o[i].first-o[j].first)+(o[i].second-o[j].second)*(o[i].second-o[j].second); } int main(){ int n,d,x,y; scanf("%d%d",&n,&d); for(int i=1;i<=n;++i) scanf("%d%d",&o[i].first,&o[i].second),fa[i]=i; char s[10]; while(~scanf("%s",s)){ if(s[0]=='O'){ scanf("%d",&x); if(vis[x])continue; for(int i=1;i<=n;++i){ if(!vis[i]||dis(x,i)>d*d)continue; int u=find(x),v=find(i); if(u!=v)fa[u]=v; } vis[x]=true; } else { scanf("%d%d",&x,&y); x=find(x),y=find(y); if(x==y)printf("SUCCESS\n"); else printf("FAIL\n"); } } return 0; }
View Code
相关文章推荐
- Java Socket应用
- iOS - 计步器
- IMF传奇行动第85课:Spark Streaming第四课:基于HDFS的Spark Streaming案例实战和内幕源码解密
- 20145328 《Java程序设计》实验四实验报告
- Java实现服务器端动态流断点续传下载支持
- PyQt5教程——菜单和工具栏(3)
- 网络七层协议
- 简单的http过滤模块
- 【LeetCode】Power of Four 解题报告
- DP 动态规划 Problem J 1010 上楼梯问题
- WebSphere8.5的安装
- 剑指offer(65):获取数据流中的中位数
- nodejs 生产环境配置
- hdu1297Children’s Queue (递推+大数)
- 研究生第二三课 软件工程&电子商务
- 网络设备互联技术· 『1』
- java之Map接口
- java实用工具之XOM
- Atom 和 markdown 基本使用
- 文件的定位