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(附codes)

Posted by RUNSLOWLY at 2009-02-17 18:24:38 on Problem 1251
#include<iostream>
using namespace std;
int main()
{
	int map[30][30],i,j,sum,n,num,min,k;
	char c[2],b[2];
	while(1)
	{
		for(i=0;i<=27;i++)
			for(j=0;j<=27;j++)
				map[i][j]=200;
		cin>>n;
		if(n<=0)
			break;
		sum=0;
		for(i=0;i<n-1;i++)
		{
			cin>>c;
			cin>>num;
			for(j=0;j<num;j++)
			{
				cin>>b;
			    cin>>min;
				map[c[0]-'A'][b[0]-'A']=map[b[0]-'A'][c[0]-'A']=min;
			}
		
		}
		for(i=0;i<n-1;i++)
		{
			min=200;
			for(j=0;j<n;j++)
			{
				if(map[i][j]<min)
				{
					min=map[i][j];
					k=j;
				}
			}
			map[k][i]=200;
			if(min<200)
	    		sum+=min;
		}
		cout<<sum<<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