| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我的WA了,能出测试数据结果的。用Prime#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator