题目链接:here
PS:第一次自己看英文!!第一次不是百度的题意!!!!
题意:东南亚大地震。。他们电脑全坏了。(我去质量真差,神舟的么)。然后人要过去修。。需要把电脑都联网,但是硬件限制,所以电脑只能在 d 距离内成功联网。。。第一行输入电脑个数n和d的值,接着n行,是n个电脑的坐标。。然后接下来有操作。。。O代表修第几台电脑,S代表检测 两台电脑是否已经联网。。。注意这里要用EOF来结束输出。。。(我在这就卡住了半天。。。)
代码:
#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
using namespace std;
const int maxn = 1005;
struct Node
{
int x, y;
}node[maxn];
int fa[maxn];
int n, d;
vector<int> v;
int num;
int find(int x)
{
while (x != fa[x]) x = fa[x];
return x;
}
bool judge(int x, int y)
{
int xx = abs(node[x].x-node[y].x), yy = abs(node[x].y-node[y].y);
if (xx*xx + yy*yy <= d*d)
return true;
return false;
}
void union_set(int x)
{
int fax = find(x);
for (int i=0; i<num; i++)
{
int fai = find(v[i]);
if (fai != fax && judge(x, v[i]))
fa[fai] = fax;
}
}
int main()
{
while (scanf("%d %d", &n, &d) != EOF)
{
int i;
num = 0;
v.clear();
for (i=1; i<=n; i++)
{
fa[i] = i;
scanf("%d %d", &node[i].x, &node[i].y);
}
getchar();
char c;
while (scanf("%c", &c) != EOF)
{
if (c == 'O')
{
int j;
scanf("%d", &j);
union_set(j);
num ++;
v.push_back(j);
}
else if (c == 'S')
{
int a, b;
scanf("%d %d", &a, &b);
if (find(a) == find(b)) puts("SUCCESS");
else puts("FAIL");
}
getchar();
}
}
return 0;
}