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 |
scanf("%*c%c %d")报错,scanf("%s %d")0MS通过,没天理啊//Prim算法 #include<stdio.h> #include<string.h> int AdjMatrix[27][27];//0不用 int vexnum; int Flag[27]; int CloseEdge[27];//0不用 void AdjustClE(int vex) { CloseEdge[vex]=200; Flag[vex]=0; for(int i=1;i<=vexnum;i++) { if(Flag[i]) { if(AdjMatrix[i][vex]<CloseEdge[i]) CloseEdge[i]=AdjMatrix[i][vex]; } } } int GetMin() { int index=0; for(int i=1;i<=vexnum;i++) { if(Flag[i]&&!index)index=i; if(Flag[i]&&(CloseEdge[index]>CloseEdge[i]))index=i; } return index; } void init() { for(int i=0;i<27;i++) { Flag[i]=1;CloseEdge[i]=200; } for(int i=0;i<27;i++) for(int j=0;j<27;j++) AdjMatrix[i][j]=200; } int main() { int N,K,row,col,sum; char vex[2]; while(1) { sum=0; init(); scanf("%d",&N); if(0==N) return 0; vexnum=N; while(--N) { scanf("%s %d",vex,&K); row=vex[0]-'A'+1; int wet; while(K--) { scanf("%s %d",&vex,&wet); col=vex[0]-'A'+1; AdjMatrix[row][col]=wet; AdjMatrix[col][row]=wet; } } int index=1; for(int i=1;i<vexnum;i++) { AdjustClE(index); index=GetMin(); //printf("%d\n",index); sum+=CloseEdge[index]; } 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