上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 30 下一页
  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) 编辑
  2012年8月26日
摘要: 我用的是Floyd算法求所有定点的最短边,这道题需要判重,由于我对于图论没啥经验,WA了N次。似乎判断d[i][j] + d[k][j]是否溢出的判断条件有小错误额。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintSIZE=1010;constintINF=0x3fffffff;intd[SIZE][SIZE];intn,m;voidFloyd(){inti,j,k;for(k=0;k<n;k++)for(i=0;i<n;i++ 阅读全文
posted @ 2012-08-26 21:14 有间博客 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 先试了试Floyd算法,结果没弄出来。然后试了试单源Dijsktra最短路径,两层循环找出最小的结果,建图的过程中遇到了小麻烦,有时间的话再写一写Floyd算法。CODE:#include<cstdio>#include<cstdlib>#include<string>usingnamespacestd;constintSIZE=1010;constintINF=0x3fffffff;intw[SIZE][SIZE];intv[SIZE],d[SIZE];intT,S,D,tot;intlink[SIZE],want[SIZE];intmax(intx,in 阅读全文
posted @ 2012-08-26 19:45 有间博客 阅读(247) 评论(0) 推荐(0) 编辑
摘要: 图论入门题。第一次写的时候用的是比较麻烦的模板,第二次写的时候模板精简多啦。还得要多多努力~较麻烦的模板,CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintINF=0x0fffffff;constintSIZE=110;intgraph[SIZE][SIZE];intvis[SIZE],dis[SIZE];intn,m;voidDijkstra(intsrc){inti,j;intmin,v;for(i=1;i<=n;i++)dis[i 阅读全文
posted @ 2012-08-26 10:29 有间博客 阅读(162) 评论(0) 推荐(0) 编辑
摘要: HDU最短路题目:1.题号:2544难度:1题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2544分析小结:入门级别,甚至floyd都可以过。2.题号:2066难度:2题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2066分析小结:也是入门级别,求起点集合到终点集合的最短路。3.题号:2112难度:3题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2112分析小结:如果会用map容易,那么这题就是一道十足的水题,我用dijkstra O(n^2)的算法过 阅读全文
posted @ 2012-08-26 09:01 有间博客 阅读(3595) 评论(1) 推荐(0) 编辑
  2012年8月25日
摘要: 第一次AC时,用的是Kruskal算法&并查集,现在用Prim实现一次。麻烦点的CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintSIZE=101;constintINF=0x7fffffff;intgraph[SIZE][SIZE];//存储图结构intvis[SIZE];//标记是否走过intdis[SIZE];//存储最小边intn;voidinit(){memset(vis,0,sizeof(vis));memset(grap 阅读全文
posted @ 2012-08-25 21:03 有间博客 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 欧拉函数的应用,以后看到互质的数第一个就要想到欧拉函数。今天又学到了好多家伙。欧拉定理:欧拉定理表明,若n,a为正整数,且n,a互质,(a,n) = 1,则a^φ(n) ≡ 1 (mod n)费马小定理:且(a,p)=1,那么 a^(p-1) ≡1(mod p) 假如p是质数,且a,p互质,那么 a的(p-1)次方除以p的余数恒等于1 。筛选法求欧拉函数,时间复杂度O(nloglogn), CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>using 阅读全文
posted @ 2012-08-25 13:51 有间博客 阅读(2817) 评论(0) 推荐(0) 编辑
摘要: 简单模拟。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>#include<math.h>usingnamespacestd;constintSIZE=10001;intprime[SIZE];intvis[SIZE]={0};intcnt;voidinit(){inti,j;cnt=0;for(i=2;i<SIZE;i++)if(!vis[i]){prime[cnt++]=i;for(j=i*i;j<SIZE;j+= 阅读全文
posted @ 2012-08-25 11:28 有间博客 阅读(130) 评论(0) 推荐(0) 编辑
上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 30 下一页