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

C++交AC,G++交WA,表示不造为啥!!!

Posted by 1871168524 at 2014-11-13 23:44:32 on Problem 2560
#include<stdio.h>
#include<string.h>
#include<math.h> 
#define INF 0x3f3f3f3f
typedef struct
{
	double x,y;
}nd;
nd node[105];
int visit[105],n;
double map[105][105],dis[105];
double jl(nd a,nd b)
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void prim()
{
	double length=0,min;
	int i,j,point=1;
	for(i=1;i<=n;i++)
	  dis[i]=map[point][i];
	memset(visit,0,sizeof(visit));
	visit[point]=1;
	for(i=1;i<n;i++)
	{
		min=INF;
		for(j=1;j<=n;j++)
		  if(!visit[j]&&dis[j]<min)
		  {
		  	 min=dis[j];
		  	 point=j;
		  }
		length+=min;
		visit[point]=1;
		for(j=1;j<=n;j++)
		  if(!visit[j]&&dis[j]>map[point][j])
		     dis[j]=map[point][j];
	}
	printf("%.2lf\n",length);
}
int main()
{
	int i,j;
	while(~scanf("%d",&n))
	{
	    for(i=1;i<=n;i++)
		{
			scanf("%lf%lf",&node[i].x,&node[i].y);
			for(j=1;j<=n;j++)
			  map[i][j]=map[j][i]=jl(node[i],node[j]);
		    map[i][i]=INF;
		}
		prim();
	}
	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