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 printf AC的代码 貌似用 " %*c " 就RE......

Posted by SUT at 2011-08-11 19:02:03 on Problem 1251
/**********POJ1251***AC***0MS***Kruskal***

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

struct Edge
{
	int from,to,len;
}edge[200];

int n,father[100];

int find(int x)
{
	int temp,root=x;
	while(root!=father[root])
	{
		root=father[root];
	}
	while(x!=root)
	{
		temp=father[x];
		father[x]=root;
		x=temp;
	}
	return root;
}

int Kruskal()
{
	int i,root1,root2,count=0,ans=0;
	for(i=0;count<n-1;i++)
	{
		root1=find(edge[i].from),root2=find(edge[i].to);
		if(root1!=root2)
		{
			father[root1]=root2;
			count++;
			ans+=edge[i].len;
		}
	}
	return ans;
}

int cmp(const void *a,const void *b)
{
	return (*(struct Edge *)a).len - (*(struct Edge *)b).len;
}

int main()
{
	int i,j,m,t,c,c1,count;
	while(scanf("%d",&n),n)
	{
		getchar();
		for(i=1;i<=n;i++)
		{
			father[i]=i;
		}
		for(count=0,i=1;i<n&&scanf("%c%c%d",&c,&c1,&m);i++)
		{
			getchar();
			for(j=1;j<=m;j++)
			{
				scanf("%c%c%d",&c,&c1,&edge[count].len);
				edge[count].from=i,edge[count].to=c-'A'+1;
				count++;
				getchar();
			}
		}
		qsort(edge,count,sizeof(edge[0]),cmp);
		printf("%d\n",Kruskal());
	}
	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