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了,能出测试数据结果的。用Prime

Posted by yuanchuanshun at 2010-05-01 14:47:55 on Problem 1258
#include<stdio.h>
int dis[102],a[102][102],flag[102];
int root=1;
int main()
{
    int i,j,n,sum; 
    while(scanf("%d",&n)!=EOF)
    {
       sum=0;
       for(i=1;i<=n;i++)
       for(j=1;j<=n;j++)
       scanf("%d",&a[i][j]);//a[i][j]表示 i 到 j 的距离; 
       dis[root]=0; flag[root]=1;
       for(i=2;i<=n;i++)
       {
          dis[i]=a[root][i];
          flag[i]=0;
       }//初始化 dis[],同时标记;
       for(i=2;i<=n;i++)
       {
          for(j=1;j<=n;j++)
          {
             if(flag[j]==0||i==j) continue;
             if(dis[i]>a[i][j]) dis[i]=a[i][j]; //更新dis[i],flag[j]=1,已经被标记; 
          }
          sum+=dis[i];
          flag[i]=1;
       }
       printf("%d\n",sum);
    }
}       

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