Poj(2236),简单并查集
2024-10-21 07:38:36
题目链接:http://poj.org/problem?id=2236
思路很简单,傻逼的我输出写成了FALL,然后遍历的时候for循环写错了,还好很快我就Debug出来了。
#include <stdio.h> struct Point
{
int x,y;
} points[]; int father[];
bool vis[]= {false}; int Find_Set (int x)
{
if(x!=father[x])
father[x] = Find_Set(father[x]);
return father[x];
} int main()
{ int N,d;
scanf("%d%d",&N,&d); for(int i=; i<=N; i++)
father[i] = i; for(int i=; i<=N; i++)
scanf("%d%d",&points[i].x,&points[i].y);
getchar(); char ch;
while(scanf("%c",&ch)!=EOF)
{
getchar();
int n,m;
if(ch=='O')
{
scanf("%d",&n);
getchar();
vis[n] = true; for(int i=; i<=N; i++)
{
if(i!=n&&vis[i])
{
int tx = points[n].x - points[i].x;
int ty = points[n].y - points[i].y;
if(tx*tx+ty*ty<=d*d)
{
int fx = Find_Set(i);
int fy = Find_Set(n); if(fx!=fy)
father[fy] = fx;
}
}
}
}
else
{
scanf("%d%d",&n,&m);
getchar(); int fx,fy;
fx = Find_Set(n);
fy = Find_Set(m);
if(fx!=fy)
printf("FAIL\n");
else printf("SUCCESS\n"); }
} return ;
}
最新文章
- SCOI2010游戏
- 3 WPF之从0开始学习XMAL
- Python之路----数据类型
- MultipeerConnectivity
- 2014第35周三jquery最近用到的内容总结
- 收集整理的非常有用的PHP函数
- <;转载>; UE4的Actor类C++简单尝试
- Win32程序框架
- base64详解及实现
- 查找第K小的数 BFPRT算法
- 混合模式为什么成为占有率最高的app开发技术
- watch解放你的双手
- RMAN入门——简介
- ES6 Module的语法
- hdu 1698 线段树(成段替换 区间求和)
- hanlp中文自然语言处理的几种分词方法
- Ubuntu13.04下Eclipse中文乱码解决
- JS拖拽事件
- Android演示Stack(课下作业)
- linux多线程同步
热门文章
- eclipse中找不到base64包的解决方法
- 单点登录-JWT(Json Web Tokens)
- (转)Linux系统排查4——网络篇
- jemeter排至数据库时报:Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password:YES) 解决方案
- C语言测试int型数据的最大值最小值
- eclipse中使用git下载项目
- http method and status code
- 使用InstallShield打包VS程序
- 文件监控只FileSystemWatcher控件
- c# 字符串大小写混合转换