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

RP太有问题了。跟大牛的代码几乎一样了都还WA?谁帮我找找错误呀,跪谢

Posted by wangfengbo at 2008-05-24 11:00:55 on Problem 1122
#include <iostream>
#include <cstdio>
#include <sstream>
#include <algorithm>
#define MAX 1000000
using namespace std;

struct ANS
{
	int time,path[21],org,len;
}ans[21];

bool operator < (ANS p,ANS q)
{
	return p.time < q.time;
}

int main()
{
	int u,min,len[21],length[21],i,j,n,k,count,start[21],dest,pth[21][21],map[21][21];
	bool v[21];
	stringstream ss;
	freopen("in.txt","r",stdin);
	//read data
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			scanf("%d",&map[i][j]);
			if(map[i][j]==-1)
				map[i][j] = MAX;
		}
	}
	scanf("%d",&dest);
	count=0;
	while(scanf("%d",&start[count])!=EOF)count++;
	// solve
	for(i=0;i<count;i++)
	{
		if(start[i]==dest)
		{
			ans[i].time = 0;
			ans[i].org = dest;
			ans[i].len = 0;
			continue;
		}
		// dijskra
		k = start[i];
		memset(v,false,sizeof(v));
		memset(length,0,sizeof(length));
		for(j=1;j<=n;j++)
			len[j] = map[k][j];
		v[k] = true;
		while(k!=dest) // find the path
		{
			min = MAX;
			for(j=1;j<=n;j++)
			{
				if(j==k || v[j])continue;
				if(len[j] > len[k]+map[k][j])
				{
					len[j] = len[k]+map[k][j];
					memcpy(pth[j],pth[k],length[k]*4);
					length[j]=length[k]+1;
					pth[j][length[j-1]] = k;  // record path
				}
				// find the minmam   mix tow procedure into one  good
				if(len[j] < min)
				{
					min = len[j];
					u = j;
				}
			}
			k = u;
			v[k] = true;
		}
		ans[i].len = length[dest];
		ans[i].org = start[i];
		ans[i].time = len[dest];
		memcpy(ans[i].path,pth[dest],len[dest]*4);
	}
	sort(ans,ans+count);
	printf("%s\t%s\t%s\t%s\n","Org","Dest","Time","Path");
	for(i=0;i<count;i++)
	{
		printf("%d\t%d\t%d\t%d",ans[i].org,dest,ans[i].time,ans[i].org);
		for(j=0;j<ans[i].len;j++)
			printf("\t%d",ans[i].path[j]);
		if(dest!=ans[i].org)
			printf("\t%d",dest);
		printf("\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