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!谢谢啦!!!

Posted by fen at 2010-09-14 16:04:45 on Problem 2485
#include<stdio.h>
#include<string.h>
#define max 10000000
#define N 503
int a[N][N],dis[N];
int m,mina;
int prim(){
	int i,j,k,min;
	mina=0;
	for(i=1;i<=m;i++)
	  dis[i]=a[1][i];
	for(i=2;i<=m;i++){
		min=max;
		for(j=1;j<=m;j++)
		  if(dis[j]!=0&&dis[j]<min){
		    min=dis[j];
		    k=j;
		  }
		  dis[j]=0;
		  if(mina<min)mina=min;
		  for(j=1;j<=m;j++)
		    if(a[k][j]!=0&&a[k][j]<dis[j])
		      dis[j]=a[k][j];
	}
	printf("%d\n",mina);
}
int main()
{
	int i,j,t;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&m);
		memset(dis,max,sizeof(dis));
		for(i=1;i<=m;i++)
		  for(j=1;j<=m;j++)
		     scanf("%d",&a[i][j]);
		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