Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求哪位大牛看看那里错了WA

Posted by louchiheng at 2016-03-31 13:18:13 on Problem 2236
#include<iostream>
#include<cstdio>
#include<string.h>
#include<cmath>
using namespace std;
struct xy
{
	long long x,y;
}a[1002];
long long f[1002],x,y,i,n,j;
double d;
char ch[1];
bool b[1002];
int getfather(int x)
{
	if(f[x]==x)return x;
	f[x]=getfather(f[x]);
	return f[x];
}
void hb(int x,int y)
{
	f[getfather(y)]=getfather(x);
}
double dis()
{
	return sqrt(1.0*(a[i].x-a[j].x)*(a[i].x-a[j].x)+1.0*(a[i].y-a[j].y)*(a[i].y-a[j].y));
}
bool judge(int x,int y)
{
	if(getfather(x)==getfather(y))return 1;
	return 0;
}
int main()
{
	scanf("%d%lf",&n,&d);
	memset(b,0,sizeof(b));
	for(i=1;i<=n;++i)
	{
	    scanf("%d%d",&a[i].x,&a[i].y);
	    f[i]=i;
    }
	while(scanf("%s",ch)!=EOF)
	{
		if(ch[0]=='O')
		{
			scanf("%d",&i);
			for(j=1;j<=n;++j)if(b[j]&&i!=j&&dis()<=d)
			if(x<y)hb(x,y);else hb(y,x);
			b[i]=1;
		}
		if(ch[0]=='S')
		{
			scanf("%d%d",&x,&y);
			if(judge(x,y))printf("SUCCESS\n");else printf("FAIL\n");
		}
	}   
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator