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

全弄错了,修改,AC 16MS

Posted by yuanchuanshun at 2010-05-01 15:13:15 on Problem 1258
In Reply To:我的WA了,能出测试数据结果的。用Prime Posted by:yuanchuanshun at 2010-05-01 14:47:55
#include<stdio.h>
int dis[102],a[102][102],flag[102];
int root=1;
int main()
{
    int i,j,k,n,sum,time,Dis; 
    while(scanf("%d",&n)!=EOF)
    {
       sum=0;k=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;//0表示该点未加入到树中; 
       }//初始化 dis[],同时标记;
       for(time=1;time<n;time++)
       {
          Dis=100000000;
          for(i=1;i<=n;i++)
          {
             if(flag[i]==1) continue;
             if(dis[i]<Dis)
             { Dis=dis[i]; k=i; }
          }
          sum+=Dis;
          flag[k]=1;
          for(j=1;j<=n;j++)
          {
             if(flag[j]==1) continue;//flag[j]==1则该点已在树中,无需更新; 
             else
             {
                 int t=10000000;
                 for(k=1;k<=n;k++) 
                 {
                    if(flag[k]==0) continue;
                    if(a[k][j]<t) t=a[k][j];
                 }
                 dis[j]=t;
             } 
          }
       }
       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