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

看了各位大虾的提示,终于AC了……贡献了3次wa……顺便问下0ms怎么出来的啊?

Posted by Web_Board at 2009-03-21 15:40:09 on Problem 1258
#include<stdio.h>
__int64 Prim(int ma[101][101],int n)
{
	int i,j,k,min;
	__int64 result=0;
	int cost[101],bo[101]={0};
	bo[1]=1;
	for(i=2;i<=n;i++)
		cost[i]=ma[1][i];
	for(i=1;i<n;i++){
		min=100001;
		for(j=2;j<=n;j++)
			if(!bo[j]&&cost[j]<min){
				k=j;
				min=cost[j];
			}
		result+=min;
		bo[k]=1;
		for(j=2;j<=n;j++)
			if(!bo[j]&&cost[j]>ma[k][j])
				cost[j]=ma[k][j];
	}
	return result;
}

int main()
{
	int ma[101][101];
	int i,j,n;
	while(scanf("%d",&n)!=EOF){
		if(!n)
			return 0;
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				scanf("%d",&ma[i][j]);
		printf("%I64d\n",Prim(ma,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