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了数次,总算prim飘过,没初始化,我好郁闷!!!!

Posted by acElvis at 2014-07-30 20:58:23 on Problem 2349
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
double map[600][600],lenth[600],sum[600],a[600];
int visit[600];
int cmp(const void*a,const void*b)
{
return ((*(double*)b>*(double*)a>0)?1:-1);
}
double  cal(double x1,double y1,double x2,double y2 )
{
   return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); 
}
struct node
{
	double x,y;
}dis[600];

int main()
{
	int case1,num,i,j,i1,j1,num1,num2,mark=0,k;
	double temp,l=0;
	while(scanf("%d",&case1)!=EOF)
	{
		while(case1--)
		{
			memset(map,0,sizeof(map));
			memset(visit,0,sizeof(visit));
			memset(sum,0,sizeof(sum));
			memset(lenth,0,sizeof(lenth));
			memset(a,0,sizeof(a));
			scanf("%d%d",&num1,&num2);
			for(i=1;i<=num2;i++)
				scanf("%lf%lf",&dis[i].x,&dis[i].y);
			for(i=1;i<=num2-1;i++)
				for(j=i+1;j<=num2;j++)
					map[i][j]=map[j][i]=cal(dis[i].x,dis[i].y,dis[j].x,dis[j].y);
			for(i=1;i<=num2;i++)//将1选为第一个点,从1出发的各个长度
				lenth[i]=map[1][i];
			visit[1]=1;
			mark=1;
			sum[1]=0;
			for(i=1;i<=num2-1;i++)//进行num2次
			{
				temp=10000000000;
			for(j=1;j<=num2;j++)
			{
				if(temp>lenth[j]&&visit[j]==0)
				{
					temp=lenth[j];
					mark=j;
				}
			}
			lenth[mark]=0;
			visit[mark]=1;
			sum[mark]=temp;
			for(j=1;j<=num2;j++)
				if(lenth[j]>map[mark][j]&&visit[j]==0)
					lenth[j]=map[mark][j];
			}
			qsort(sum,num2+1,sizeof(sum[0]),cmp);
			printf("%.2lf\n",sum[num1-1]);

		}
	}
}

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