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

1A飘过啦啦,prime就是好用,cc

Posted by acElvis at 2014-07-31 15:08:15 on Problem 1258
#include<stdio.h>
#include<string.h>
#define crl(r) memset(r,0,sizeof(r))
int mark, num,map[110][110],visit[110],wri[110];
int prime()
{
	int i,j,i1,result;
	result=0;
    for(i=1;i<=num-1;i++)
	{
	  int min=10000000;
	  for(j=1;j<=num;j++)
	  {
	      if(wri[j]<min&&visit[j]==0)
		  {
			  min=wri[j];
		       mark=j;
		  }
	  }
	  result+=min;
	  wri[j]=0;
	  visit[mark]=1;
	  for(j=1;j<=num;j++)
	  {
		  if(map[mark][j]<wri[j]&&visit[j]==0)
			 wri[j]=map[mark][j];
	  }
	}
  return result;
}
int main()
{
	int i,j,s;
     while(scanf("%d",&num)!=EOF)
	 {
		 crl(visit);
		 crl(wri);
	 for(i=1;i<=num;i++)
		 for(j=1;j<=num;j++)
			scanf("%d",&map[i][j]);
	 for(i=1;i<=num;i++)
		 wri[i]=map[1][i];
         visit[1]=1;
		 mark=1;
		 s=prime();
		 printf("%d\n",s);
	 }
}

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