2012年8月27日
摘要: 最短路径问题,Floyd算法。英文较难看懂,数据处理比较困难。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintSIZE=101;constintINF=0x3fffffff;intn;intd[SIZE][SIZE],sea[SIZE];voidFloyd(){inti,j,k;for(k=0;k<n;k++)for(i=0;i<n;i++)for(j=0;j<n;j++)if(d[i][j]<=INF&&a 阅读全文
posted @ 2012-08-27 18:08 有间博客 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 题意简洁,最小生成树问题。通过Prim算法求解,数据的处理有点困难。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintSIZE=110;constintINF=0x0fffffff;intw[SIZE][SIZE];intv[SIZE],d[SIZE];intn;intPrim(intsrc){inti,j;inttot=0;memset(v,0,sizeof(v));for(i=1;i<=n;i++)d[i]=(i==src)?0:I 阅读全文
posted @ 2012-08-27 16:21 有间博客 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 可以用最短路算法的原理MST性质去思考这道题,于是就有了Dijkstra算法的变形。注意当安全值为0时表示不连通。精简的CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintSIZE=1010;constintINF=-110;doublew[SIZE][SIZE];doubled[SIZE];intv[SIZE];intn;voidDijkstra(ints,inte)//start,end;{inti,j;memset(v,0,sizeof( 阅读全文
posted @ 2012-08-27 13:07 有间博客 阅读(207) 评论(0) 推荐(0) 编辑