Poj(2236),简单并查集
题目链接: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 ;
}
Poj(2236),简单并查集的更多相关文章
- POJ 2236 (简单并查集) Wireless Network
题意: 有n个电脑坏掉了,分别给出他们的坐标 有两种操作,可以O x表示修好第x台电脑,可以 S x y表示x y是否连通 两台电脑的距离不超过d便可连通,两台电脑是连通的可以直接连通也可以间接通过第 ...
- POJ 2524 (简单并查集) Ubiquitous Religions
题意:有编号为1到n的学生,然后有m组调查,每组调查中有a和b,表示该两个学生有同样的宗教信仰,问最多有多少种不同的宗教信仰 简单并查集 //#define LOCAL #include <io ...
- poj 2236【并查集】
poj 2236 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical t ...
- POJ 2492 (简单并查集) A Bug's Life
题意:有编号为1~n的虫子,开始假设这种昆虫是异性恋.然后已知xi 和 yi进行交配,根据已知情况分析能否推理出其中是否有同性恋 这道题和 POJ 1182 食物链 十分相似,不过在更新与父节点关系的 ...
- poj 1611 简单并查集的应用
#include<stdio.h> #define N 31000 int pre[N]; int find(int x) { if(x!=pre[x]) pre[x]=find( ...
- poj1611 简单并查集
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 32781 Accepted: 15902 De ...
- 1213 How Many Tables(简单并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 简单并查集,统计单独成树的数量. 代码: #include <stdio.h> #i ...
- 【简单并查集】Farm Irrigation
Farm Irrigation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tot ...
- ACM_“打老虎”的背后(简单并查集)
“打老虎”的背后 Time Limit: 2000/1000ms (Java/Others) Problem Description: “习大大”自担任国家主席以来大力反腐倡廉,各地打击贪腐力度也逐步 ...
随机推荐
- Ubuntu 安装 phpredis扩展
官网 https://github.com/phpredis/phpredis 下载->然后解压->上传服务器 /etc/phpredis 进行 cd /etc/phpredisphpiz ...
- java——变量
1.静态变量: 随着类的加载而生成并初始化 随着类的消失而消失 2.成员变量: 随对象的加载而生成并初始化 随对象被回收而消失 3.局部变量: 作用范围由{}决定 随方法调用而创建 随方法的执行完毕而 ...
- 配置编译器(GCC和GFortran)
平台信息 Description: CentOS Linux release 7.6.1810 (Core) 检查环境 $ gfortran -v $ gcc -v 安装 GCC和Fortran 环境 ...
- android Binder机制(一)架构设计
Binder 架构设计 Binder 被设计出来是解决 Android IPC(进程间通信) 问题的.Binder 将两个进程间交互的理解为 Client 向 Server 进行通信. 如下:bind ...
- virtualenv(for python)
完整: http://docs.jinkan.org/docs/flask/installation.html#installation virtualenv 你很可能想在开发中用上 virtua ...
- python处理编码问题和JSON格式
从文件读出数据:默认utf8编码 json.dumps()输出数据:默认unicode编码 json读取(json是种通用的数据传输格式) import ujson as json #for perf ...
- STM32F3 浮点运算使用
在keil中使用浮点运算的步骤:在程序中包含#include <math.h>
- CAD安装失败怎样卸载CAD 2017?错误提示某些产品无法安装
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- ubuntu安装软件依赖解决
sudo apt-get install -f zsh@zsh:~/Downloads/dist$ sudo dpkg --install Kitematic_0.17.3_amd64.deb (正在 ...
- IIS/asp.net管道
http://referencesource.microsoft.com/ 理解ASP.NET的前提是对ASP.NET管道式设计的深刻认识.而ASP.NET Web应用大都是寄宿于IIS上的. IIS ...