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 |
1A飘过啦啦,prime就是好用,cc#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator