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 luosiyong at 2008-08-05 15:04:47 on Problem 1062
#include <iostream>
using namespace std;
#define N 101

int m,n;
int dis[N][N];
int l[N];
bool use[N];

inline int Abs(int a)
{
	return a>0 ? a : -a;
}

int ReadData()
{
	if(scanf("%d%d",&m,&n)==EOF)
		return 0;
	memset(dis,-1,sizeof(dis));
	int i,j,cnt;
	for(i=1;i<=n;i++)
	{
		scanf("%d%d%d",&dis[0][i],&l[i],&cnt);
		int t,v;
		for(j=0;j<cnt;j++)
		{
			scanf("%d%d",&t,&v);
			dis[t][i]=v;
		}
	}
	for(i=1;i<=n;i++) //如果等级差超过了m的处理掉
	{
		for(j=1;j<=n;j++)
		{
			if(i==j || Abs(l[i]-l[j])<=m)
				continue;
			dis[i][j]=dis[j][i]=-1;
		}
	}
	return 1;
}

int ChooseMin()
{
	int res=-1;
	int i;
	for(i=1;i<=n;i++)
	{
		if(! use[i] && (res==-1 || dis[0][i]<dis[0][res]))
			res=i;
	}
	return res;
}

void Dijkstra()
{
	memset(use,false,sizeof(use));
	int cnt;
	for(cnt=0;cnt<n;cnt++) //逐个把n个点加入到已访问的集合
	{
		int Min=ChooseMin();
		use[Min]=true;
		int i;
		for(i=1;i<=n;i++)
		{
			if(use[i])
				continue;
			if((dis[0][Min]!=-1 && dis[Min][i]!=-1 && dis[0][i]==-1) || (dis[0][Min]!=-1 && dis[Min][i]!=-1 && dis[0][Min]+dis[Min][i]<dis[0][i]))
				dis[0][i]=dis[0][Min]+dis[Min][i];
		}
	}
}

int main()
{
	while(ReadData())
	{
		Dijkstra();
		printf("%d\n",dis[0][1]);
	}
	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