| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
检查一下啊!#include <iostream>
#include <string>
using namespace std;
#define M 1010
typedef struct point
{
int x;
int y;
}point;
point p[M];
int father[M];
bool flag[M];
int n,d;
void make_set()
{
for(int i=1;i<=M;i++)
father[i]=i;
memset(flag,false,sizeof(flag));
}
int find(int x)
{
return father[x]==x?x:father[x]=find(father[x]);
}
void unionset(int a,int b)
{
a=find(a);
b=find(b);
if(a!=b&&(p[a].x-p[b].x)*(p[a].x-p[b].x)+(p[a].y-p[b].y)*(p[a].y-p[b].y)<=d*d)
father[a]=b;
}
int main()
{
int i,j;
char str;
scanf("%d%d",&n,&d);
for(i=1;i<=n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
int id;
make_set();
while(scanf("%c",&str)!=EOF)
{
if(str=='O')
{
scanf("%d",&id);
flag[id]=true;
for(i=1;i<=n;i++)
if(flag[i]==true&&i!=id)
unionset(i,id);
}
else
if(str=='S')
{
scanf("%d %d",&i,&j);
if(find(i)==find(j))
printf("SUCCESS\n");
else
printf("FAIL\n");
}
}
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator