| ||||||||||
| 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 | |||||||||
C++->WA,G++->AC,是神马情况#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
/************************/
int f[1020];
bool vis[1020];
struct data{
int x,y;
}poi[1020];
/************************/
void init()
{
int i;
for(i=0;i<=1020;i++)
f[i]=i;
}
int getf(int x)
{
if(x!=f[x])
f[x]=getf(f[x]);
return f[x];
}
void hebi(int x,int y)
{
int a,b;
a=getf(x);b=getf(y);
if(a!=b)
f[a]=b;
}
double check(int p,int i)
{
return (poi[p].x-poi[i].x)*(poi[p].x-poi[i].x)+(poi[p].y-poi[i].y)*(poi[p].y-poi[i].y);
}
/************************/
int main()
{
char str[3];int p,q,n,d;
scanf("%d%d",&n,&d);
int i;
// memset(vis,false,sizeof(vis));
for(i=1;i<=n;i++)
scanf("%d%d",&poi[i].x,&poi[i].y);
init();
while(scanf("%s",str)!=EOF)
{
if(str[0]=='O')
{
scanf("%d",&p);
vis[p]=true;
for(i=1;i<=n;i++)
{
if(vis[i]&&check(p,i)<=d*d+0.000000001)
hebi(p,i);
}
}
else
{
int a,b;
scanf("%d%d",&p,&q);
a=getf(p);b=getf(q);
if(a==b)
{
printf("SUCCESS\n");
}
else
printf("FAIL\n");
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator