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

这题没有问题,用scanf可以过的。

Posted by 101240 at 2011-10-26 00:27:44 on Problem 1251
用%s 就可以了

#include<stdio.h>
#include<stdlib.h>

typedef struct {
	int v1,v2,cost;
}Link;
Link L[1000];

int cmp(const void *a , const void *b)
{
	return ((Link *)a) -> cost - ((Link *)b) -> cost;
}

int find(int father[],int v)
{
	int t;

	t=v;
	while(father[t]>=0)
		t=father[t];

	return t;
}

int main()
{
	int i,n,k,s,t,father[1000],count,sum,vf1,vf2;
	char a[1000];

	while(scanf("%d",&n)!=EOF)
	{
		if(n==0)
			break;

		getchar();

		count=0;
		for(i=1;i<n;i++)
		{
			scanf("%s%d",a,&k);
			s=a[0]-64;
			
			while(k--)
			{
				scanf("%s%d",a,&t);
				L[count].v1=s;
				L[count].v2=a[0]-64;
				L[count].cost=t;
				count++;
			}

			gets(a);
		}

		qsort(L,count,sizeof(L[0]),cmp);

		for(i=1;i<=n;i++)
			father[i]=-1;

		i=sum=0;
		while(i<count)
		{
			vf1=find(father,L[i].v1);
			vf2=find(father,L[i].v2);

			if(vf1!=vf2)
			{
				father[vf2]=vf1;
				sum+=L[i].cost;
			}

			i++;
		}

		printf("%d\n",sum);

	}

	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