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 alphachuang at 2011-12-19 19:08:07 on Problem 1125
#include <iostream>
using namespace std;
#define maxTime 1000000000
int stockNum;
int time[101][101];
int main()
{
	int i,j,k;
	int contactNum,contact;
	while(cin>>stockNum&&stockNum!=0)
	{
		//initialize the array
		for(i=1;i<=stockNum;i++)
		{
			for(k=1;k<=stockNum;k++)
			{
				 time[i][k]=maxTime;
			}
		}
		//input the map
		for(i=1;i<=stockNum;i++)
		{
			cin>>contactNum;
			for(;contactNum>0;contactNum--)
			{
				cin>>contact;
	            cin>>time[i][contact];
			}
		}
		//initialize edge i to i
		/*for(i=1;i<=stockNum;i++)
		{
			time[i][i]=0;
		}*/
	    //greedy to floyd
		for(k=1;k<=stockNum;k++)
		{
			for(i=1;i<=stockNum;i++)
			{
		        if(i!=k)
				{
			        for(j=1;j<=stockNum;j++)
					{
				        if(j!=k&&j!=i&&
							time[i][k]!=maxTime&&time[k][j]!=maxTime&&
							(time[i][k]+time[k][j])<time[i][j])
						{
						    time[i][j]=time[i][k]+time[k][i];
						}
					}
				}
			}
		}
		//get final answer
		int finalans=maxTime;
	    int finalpos=0;
	    for(i=1;i<=stockNum;i++)
		{
			//find the max time to visit the map from i
		    int currAns=0;
		    for(j=1;j<=stockNum;j++)
			{
			    if(i!=j&&currAns<time[i][j])
				{
				    currAns=time[i][j];
				}
			}
			//get the min visit time
            if(finalans>currAns)
			{
			    finalans=currAns;
			    finalpos=i;
			}
		}
		//output
		cout<<finalpos<<' '<<finalans<<endl;
	}
	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