栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2236 Wireless Network

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2236 Wireless Network

#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>using namespace std;#define N 1110int d;bool use[N];struct node{int pre;int x, y;}p[N];int find(int x){return x == p[x].pre ? x : find(p[x].pre);}void join(const node p1, const node p2){int root1, root2;root1 = find(p1.pre);root2 = find(p2.pre);if(root1 != root2)if((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y) <= d * d)p[root2].pre = root1;}int main(){//freopen("Input.txt", "r", stdin);int num;char ope;int ok;int from, to;scanf("%d%d", &num, &d);for(int i = 1; i <= num; ++i)p[i].pre = i;memset(use, false, sizeof(use));for(int i = 1; i <= num; ++i)scanf("%d%d", &p[i].x, &p[i].y);while(scanf("n%c", &ope) != EOF){if(ope == 'O'){scanf("%d", &ok);use[ok] = true;for(int i = 1; i <= num; ++i)if(use[i] && i != ok)join(p[i], p[ok]);}else{scanf("%d%d", &from, &to);if(find(from) == find(to))printf("SUCCESSn");elseprintf("FAILn");}}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379025.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号