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了n次了 , 都检查不出来!!!!!!!!!!

Posted by sw1001 at 2011-04-04 19:50:34 on Problem 2236
#include <stdio.h>

typedef struct
{
	int xi;
	int yi;
}point;

point ppt[1010];
int father[1010], kind[1010];

void makeset(int n)//初始化
{
	int i;

	for(i=1;i<=n;++i)
	{
		father[i]=i;
		kind[i]=0;
	}
}


int findset(int x)//查找祖先
{

	if(x!=father[x])
	{
		father[x]=findset(father[x]);

	}

	return father[x];
}

void Union(int x, int n, double d)
{
	int i;
	
	double w;
	kind[x]=1;

	for(i=1;i<=n;++i)
	{
		if(kind[i]==1)
		{
			w=(double)((ppt[i].xi-ppt[x].xi)*(ppt[i].xi-ppt[x].xi) + (ppt[i].yi-ppt[x].yi)*(ppt[i].yi-ppt[x].yi));

			if(w<=d*d)
				father[i]=x;
		}
	}
}

int main()
{
	int n, i;
	double d;
	char c;

	int xx;

	scanf("%d%lf", &n, &d);
	
	for(i=1;i<=n;++i)
	{
		scanf("%d%d", &ppt[i].xi, &ppt[i].yi);
	}

	makeset(n);

	
	while(scanf("\n%c", &c)!=EOF)
	{
	if(c=='O')
	{
		scanf("%d", &xx);
		Union(xx, n, d);
	}
	
	else
	{
		int aai, bbi;

		scanf("%d%d", &aai, &bbi);
		if(findset(aai)==findset(bbi))
		{
			printf("SUCCESS\n");
		}
		else
		{
			printf("FAIL\n");
		}

	}
	}
	return 0;

}

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