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 |
Re:我怎么会WA了呢In Reply To:我怎么会WA了呢 Posted by:whlacm at 2010-11-13 22:41:22 我也wa了…… #include<cstdio> #include<cstdlib> #include<cstring> #define MN 105 #define INITMAX 0x1f1f1f1f int mitrix[MN][MN]; void input(int n) { int i,j,num; memset(mitrix,0x1f,sizeof(mitrix)); for(i=0;i<n;i++)mitrix[i][i]=0; for(i=1;i<n;i++) { for(j=0;j<i;j++) { if(scanf("%d",&num)) { mitrix[i][j]=mitrix[j][i]=num; } else { mitrix[i][j]=mitrix[j][i]=INITMAX; scanf("x"); } } } } int visit[MN]; void solve(int *minCost,int n,int start) { int i,j,minNode; memset(minCost,0x1f,sizeof(int)*n);//初始化到各点距离为最大 memset(visit,0,sizeof(visit)*n);//认为所有点都没访问过 minCost[n]= INITMAX;//认为最后一个是极大,便于查找最小下标 minNode = start;//把初始的松弛点设置为start minCost[start]= 0;//自己到自己是0 for(i=0;i<n;i++) { visit[minNode] = 1; //用minNode松弛 for(j=0;j<n;j++) { if((!visit[j])//没必要去松弛已经访问的结点 &&minCost[j]>mitrix[start][minNode]+mitrix[minNode][j])//可以松弛 { minCost[j] = mitrix[start][minNode]+mitrix[minNode][j]; } } minNode = n; for(j=0;j<n;j++) { if((!visit[j])&&minCost[j]<minCost[minNode]) { minNode = j; } } } } int main() { int n; int minCost[MN]; int maxValue,i; while(~scanf("%d",&n)) { input(n); solve(minCost,n,0); maxValue = -INITMAX; for(i=0;i<n;i++) { if(maxValue<minCost[i]) maxValue = minCost[i]; } printf("%d\n",maxValue); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator