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

Re:我怎么会WA了呢

Posted by hataksumo at 2012-05-29 11:40:10 on Problem 1502
In Reply To:我怎么会WA了呢 Posted by:whlacm at 2010-11-13 22:41:22
我也wa了……
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define MN 105
#define INITMAX 0x1f1f1f1f
int mitrix[MN][MN];
void input(int n)
{
	int i,j,num;
	memset(mitrix,0x1f,sizeof(mitrix));
	for(i=0;i<n;i++)mitrix[i][i]=0;
	for(i=1;i<n;i++)
	{
		for(j=0;j<i;j++)
		{
			if(scanf("%d",&num))
			{
				mitrix[i][j]=mitrix[j][i]=num;
			}
			else
			{
				mitrix[i][j]=mitrix[j][i]=INITMAX;
				scanf("x");
			}
		}
	}
}
int visit[MN];
void solve(int *minCost,int n,int start)
{
	int i,j,minNode;
	memset(minCost,0x1f,sizeof(int)*n);//初始化到各点距离为最大
	memset(visit,0,sizeof(visit)*n);//认为所有点都没访问过
	minCost[n]= INITMAX;//认为最后一个是极大,便于查找最小下标
	minNode = start;//把初始的松弛点设置为start
	minCost[start]= 0;//自己到自己是0
	for(i=0;i<n;i++)
	{
		visit[minNode] = 1;
		//用minNode松弛
		for(j=0;j<n;j++)
		{
			if((!visit[j])//没必要去松弛已经访问的结点
				&&minCost[j]>mitrix[start][minNode]+mitrix[minNode][j])//可以松弛
			{
				minCost[j] = mitrix[start][minNode]+mitrix[minNode][j];
			}
		}
		minNode = n;
		for(j=0;j<n;j++)
		{
			if((!visit[j])&&minCost[j]<minCost[minNode])
			{
				minNode = j;	
			}
		}
	}
}
int main()
{
	int n;
	int minCost[MN];
	int maxValue,i;
	while(~scanf("%d",&n))
	{
		input(n);
		solve(minCost,n,0);
		maxValue = -INITMAX;
		for(i=0;i<n;i++)
		{
			if(maxValue<minCost[i])
				maxValue = minCost[i];
		}
		printf("%d\n",maxValue);
	}
	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