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

牛人帮我看一下为什么会runtime error谢谢,实在找不出了

Posted by majia3 at 2005-07-11 19:32:10 on Problem 2236
#include<stdio.h>
#include<memory.h>
#include<math.h>
#include<string.h>
#define Size 2000

struct DisjointSet {
    long pi[Size], rank[Size];

    DisjointSet()
    {
	for (long i = 0; i < Size; i++) {
	    pi[i]   = i;
	    rank[i] = 0;
	}
    }

    long find(long x) 
    {
	while (x != pi[x])
	{
		x=pi[x];
	}
	return pi[x];
    }

    long merge(long x, long y) 
    {
	x = find(x);
	y = find(y);
	if (rank[x] > rank[y]) {
	    pi[y] = x;
	    return x;
	} else {
	    pi[x] = y;
	    if (rank[x] == rank[y]) rank[y]++;
	    return y;
	}
    }  
}s;

int main()
{
	long i,n,a[Size][Size],k,k1,k2,j,flag[Size],num;
	bool rec[Size];
	double x[Size],y[Size],d;
	char str[100];
	scanf("%d %lf",&n,&d);
	for (i=1;i<=n;i++)
	{
		scanf("%lf %lf",&x[i],&y[i]);
		for (j=1;j<=i-1;j++)
		{
			if (sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))<=d)
			{
				a[i][j]=1;
				a[j][i]=1;
			}
			else
			{
				a[i][j]=0;
				a[j][i]=0;
			}
		}
	}
	for (i=1;i<=n;i++)
		rec[i]=false;
	num=0;
	while(scanf("%s",&str)!=NULL)
	{
		if (strcmp(str,"O")==0)
		{
			scanf("%d",&k);
			if (rec[k])
				continue;
			rec[k]=true;
			num++;
			flag[num]=k;
			for (i=1;i<=num-1;i++)
				if (a[k][flag[i]]==1)
					s.merge(k,flag[i]);
		}
		else
		{
			scanf("%d %d",&k1,&k2);
			k1=s.find(k1);k2=s.find(k2);
			if (k1==k2)
				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