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

求大神解答

Posted by nenu_cs_11yanyao at 2012-03-24 08:00:51 on Problem 1258
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
__int64 d[10000],u[2000];
__int64 a[5000][5000];
__int64 f(__int64 n)
{
	__int64 i,j,k,m,b2,b1,sum,min;
	for(i=0;i<n;i++)
	{
	u[i]=0;	
	d[i]=a[0][i];
	}
	u[0]=1;
	b1=0;
	for(i=0;i<n-1;i++)
	{
		for(j=0,min=1000000;j<n;j++)
		{
			if(u[j]==0)
			if(a[b1][j]<min&&b1!=j)
			{
				min=a[b1][j];
				b2=j;
			}
		}
		u[b2]=1;
		b1=b2;
//		printf("%d\()()()n\n",b2);
		for(j=0;j<n;j++)
		{
			if(u[j]==0)
			{
			if(d[j]>a[b2][j])
				d[j]=a[b2][j];
			}
		}
	}
	for(i=0,sum=0;i<n;i++)
	{
//		printf("%d****\n",d[i]);
		sum=sum+d[i];
	}
	return sum;
	
}

int main ()
{
	__int64 n,i,j,k,m,sum;	
//	freopen("x.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	while(scanf("%I64d",&n)!=EOF)
	{
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
			scanf("%I64d",&a[i][j]);
		sum=f(n);
		printf("%I64d\n",sum);
			
	}

    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