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:prim

Posted by springtty at 2005-07-14 14:15:02 on Problem 1751
In Reply To:prim Posted by:00448242 at 2005-07-14 14:04:06
谢谢各位,现在改了,还是超,现在要用1015MS吧,我会看看你们写的,研究一下
#include <stdio.h>
#include <string.h>

#define  GetDisDB(x0,y0,x1,y1) ((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))
#define  Max  751
typedef struct
{
	int x,y;
}Point;

int HashConn[Max][Max];
int Map[Max][Max];
int SetConn[Max];
int ConnEndIndex;
int SetLeft[Max];
int LeftEndIndex;
int tmp[Max];
Point Value[Max];


void Build(int n)
{
	int a,b,i,j,v;
	int index = 0;
	int curi,curj;

	while(LeftEndIndex)
	{
		a = b = 0;
		v = 0x0FFFFFFF;
		
		for(i= 1;i<=ConnEndIndex;i++)
			for(j=1;j<=LeftEndIndex;j++)
			{			
					curi = SetConn[i];
					curj = SetLeft[j];
			 
					if((Map[curi][curj]<v))	
					{
						a = curi;
						b = curj;
						v = Map[curi][curj];
						index = j;
					}
				
			}

		if(!HashConn[a][b]) printf("%d %d\n",a,b);
		ConnEndIndex++;
		SetConn[ConnEndIndex] = b;
		
		memcpy(tmp,&SetLeft[index+1],(LeftEndIndex-index)*sizeof(int));
		memcpy(&SetLeft[index],tmp,(LeftEndIndex-index)*sizeof(int));
		LeftEndIndex--;
	}
}


int main()
{
	int i,j,n,p,a,b;
	int x,y;

	scanf("%d",&n);
	{
//		memset(Map,0,sizeof(int)*Max*Max);
//		memset(SetConn,0,Max*sizeof(int));
//		memset(SetLeft,0,Max*sizeof(int));
//		memset(Value,0,Max*sizeof(Point));
		memset(HashConn,0,sizeof(int)*Max*Max);
		
		for(i=1;i<=n;i++)
		{
			scanf("%d%d",&x,&y);
			Value[i].x = x;
			Value[i].y = y;
			SetLeft[i] = i+1;
		}
		
		for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
		{
		Map[i][j] = GetDisDB(Value[i].x,Value[i].y,Value[j].x,Value[j].y);
		Map[j][i] = Map[i][j];
		}

		scanf("%d",&p);

		for(i=1;i<=p;i++)
		{
			scanf("%d%d",&a,&b);
			Map[a][b] = 0;
			Map[b][a] = 0;
			HashConn[a][b] = 1;
			HashConn[b][a] = 1;
		}
		
		
		LeftEndIndex = n - 1;		
		
		ConnEndIndex = 1;
		SetConn[ConnEndIndex] = 1;

		Build(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