解题思路:简单并查集,注意时间限制是10000MS,每次进行O操作之后,

      进行一次for循环,进行相关调整。同时注意输入输出格式,见代码:

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = ;
int father[maxn], vis[maxn]; struct node{
double x, y; //此处用double
}p[maxn]; int Find(int x)
{
return father[x] == x ? x : father[x] = Find(father[x]);
} void Union(int x, int y)
{
int rootx = Find(x), rooty = Find(y);
if(rootx != rooty) father[rootx] = rooty;
return ;
} int main()
{
int n, d, k, a, b;
char ch;
scanf("%d %d", &n, &d);
memset(vis, , sizeof(vis));
for(int i = ; i <= n; i++) father[i] = i;
for(int i = ; i <= n; i++) scanf("%lf %lf", &p[i].x, &p[i].y);
while(~scanf(" %c", &ch))
{
if(ch == 'O')
{
scanf("%d", &k);
vis[k] = ;
for(int i = ; i <= n; i++)
{
if(!vis[i]) continue; //必须是已经修过的
//两点距离小于等于d,则可以合并
if(sqrt((p[i].x-p[k].x)*(p[i].x-p[k].x)+(p[i].y-p[k].y)*(p[i].y-p[k].y)) <= d)
Union(i, k);
}
}
else
{
scanf("%d %d", &a, &b);
//根节点相同,则表明可以连接
if(Find(a) == Find(b)) printf("SUCCESS\n");
else printf("FAIL\n");
}
}
return ;
}

最新文章

  1. ASP.NET路由模型解析
  2. 流行ORM产品优缺点分析--EntityFramework、NHibernate、PetaPoco
  3. Python基础知识(一)
  4. block、inline、inline-block
  5. 使用re-sign.jar对apk进行重签名
  6. Object 转化为String时的一个问题 null-&gt;&quot;null&quot;
  7. 阻塞通信之Socket编程
  8. Oracle 11g 7个压缩包说明
  9. iOS开发多线程篇—自定义NSOperation
  10. ios学习笔记
  11. 【EntityFramwork--处理数据并发问题】
  12. EF收集
  13. [linux]segvcatch简单使用
  14. Lua与C++的交互
  15. 由if-else,switch代替方案引起的思考
  16. Java基本数据类型的长度范围
  17. [BZOJ3011][Usaco2012 Dec]Running Away From the Barn
  18. 双目SLAM(1) 总配置
  19. Faster RCNN代码理解(Python)
  20. Github网站加载不完全,响应超时,解决办法

热门文章

  1. 使用angular.js开发的一个简易todo demo
  2. ExtJs布局之viewport
  3. WCF分布式开发步步为赢(3)WCF服务元数据交换、配置及编程开发
  4. LINUX输入输出与文件
  5. UVA 11806 Cheerleaders dp+容斥
  6. Gradle Goodness: Rename Ant Task Names When Importing Ant Build File
  7. BFS+贪心 HDOJ 5335 Walk Out
  8. Spring框架学习之第5节
  9. (转载)word-wrap,word-break,white-space,text-overflow的区别和用法
  10. Delphi动态事件深入分析(对象方法在调用的时候会传递一个隐含的Self指针,而该指针的值在EAX中。即左边第一个参数)