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

总是RE,哪位高手帮我看看错误在哪呀

Posted by wanghaishanren at 2008-05-02 18:06:29 on Problem 2236 and last updated at 2008-05-02 19:22:29
总是RE,哪位高手帮我看看错误在哪呀
#include<iostream>
#include<cmath>
using namespace std;
struct seat
{
	int x;
	int y;
};

seat seats[1050];//网络中各个计算机的坐标
int  computers[1050];//各个计算机之间的通信状态 
bool  repaired[1050];//是否已经修复过 
int maxDistance;//两计算机能直接通信时,之间的最大距离 

int find(int a)//查找a所在树的根结点,并压缩路径 
{
	if (computers[a] < 0)
		return a;
	else
	{		
		int root = find(computers[a]);
		computers[a] = root;
		return root;
	}	
}

void Union(int a,int b)//把a所在的树并入b所在的树中 
{
	int aRoot = find(a);
	int bRoot = find(b);
	computers[aRoot] = bRoot;
}


int main(void)
{
	int n;//网络中计算机的总数
	cin>>n>>maxDistance;
	
	memset(computers,-1,sizeof(int)*(1050));
	memset(repaired,false,sizeof(bool)*(1050));
	for(int i=1;i<=n;i++)
	{
		cin>>seats[i].x>>seats[i].y;
	}
	
	char op;
	int a,b;
	double space;
	int count = 1;
	while(cin>>op)
	{
		switch(op)
		{
			case 'O':
				cin>>a;
				if (a > 1001)
					break;
				repaired[a] = true;
				for(int i=1;i<a;i++)
				{
					if (repaired[i])
					{
						space = sqrt(double((seats[i].x-seats[a].x)*(seats[i].x-seats[a].x) + (seats[i].y-seats[a].y)*(seats[i].y-seats[a].y)));
						if (space <= maxDistance)
						{
							Union(a,i);
						} 											
					}//end if (repaired[i])
				}//end for
				for(int i=a+1;i<=n;i++)
				{
					if (i > 1001)
						break;
					if (repaired[i])
					{
						space = sqrt(double((seats[i].x-seats[a].x)*(seats[i].x-seats[a].x) + (seats[i].y-seats[a].y)*(seats[i].y-seats[a].y)));
						if (space <= maxDistance)
						{
							Union(a,i);
						} 											
					}//end if (repaired[i])
				}//end for
				
				break;
			case 'S':
				cin>>a>>b;
				if (a > 1001 || b > 1001)
					break;
				if (find(a) == find(b))
					cout<<"SUCCESS"<<endl;
				else
					cout<<"FAIL"<<endl;
				break;
		}//end switch
		
		if (300000 < count)
			break;
		count++;
	}//end while
		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