摘要: 以前写的报告,可以参考下http://blog.sina.com.cn/s/blog_99ca2df501019bkd.htmlView Code 1 // I'm the Topcoder 2 //C 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 #include <ctype.h> 7 #include <math.h> 8 #include <time.h> 9 //C++ 10 #include <iostream 阅读全文
posted @ 2013-03-25 23:40 南下的小程序员 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 题意:建立QS网络的最小费用。分析:运用prim算法求解最小生成树关键:本题关键是建图。在构造有向网时,每条边的权值为两个QS的适配器的加个加上两个QS之间网线的加个。这样就可以解决问题了。简化:本题只需最小生成树的权值,不需要记录构造最小生成树时选择的边,因此可以将lowcost数组和nearvex数组合二为一。自己做法还是一起解决吧,省得记那么多。呵呵View Code 1 // I'm the Topcoder 2 //C 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h& 阅读全文
posted @ 2013-03-25 21:35 南下的小程序员 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 题意:邻接村子里面所有的村庄,使得道路的总长度最小。分析:由于题意说会有已经通好道路的村庄。我们任然可以利用prim求解最小生成树,只要把已经通好道路的权值置为0,就行了。View Code 1 // I'm the Topcoder 2 //C 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 #include <ctype.h> 7 #include <math.h> 8 #include <time.h> 9 //C++ 10 阅读全文
posted @ 2013-03-25 21:18 南下的小程序员 阅读(372) 评论(0) 推荐(0) 编辑
摘要: 题意:求连接所有地点是网线长度最短分析:kruskal。一开始数组开小了 导致re了几次,然后开大后有wa 了几次,郁闷的去取了快递,吃了饭。回来在检查发现parent[]这边又出问题 了。应该是for(int i=1;i<=n;i++){ path[i]=-1;}而不是下标从0 到n-1.嗨。。。View Code 1 // I'm the Topcoder 2 //C 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 #include <ctype.h 阅读全文
posted @ 2013-03-25 17:50 南下的小程序员 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 题意:求连接所有村庄道路的最小费用。分析:kruskal算法,直接求最小生成树。注意:这题输入的时候是字母,所以要注意了。POJ如果用getchar()的话会wa。坑爹啊。还好我后来在ZOJ 上提交过了,在POJ discuss里发现说tle||re的注意了要用数组输入字母(呵呵,我的是WA),以后碰到这种还是直接用数组,省那么点空间干嘛。还有这题关键是建图,具体细则参看代码。这次代码有点乱。呵呵。见谅。View Code 1 // I'm the Topcoder 2 //C 3 #include <stdio.h> 4 #include <stdlib.h> 阅读全文
posted @ 2013-03-25 16:22 南下的小程序员 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 题意:用所给的网线链接所有的路流器,使得最长的单根网线的长度在所有方案中是最小的。分析:本质还是求最小生成树。为了输出单根网线的长度在所有方案中是最小的以及输入p对顶点,需要在选择的时候记录下已选则 的网线的下标。zoj这题80ms,而uva 前面几次tle。后面人品好点干好1s。啊。秒杀啊。擦。View Code 1 // I'm the Topcoder 2 //C 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 #include <ctype.h> 阅读全文
posted @ 2013-03-25 14:49 南下的小程序员 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 题意:给定平面上的n个城市的位置,计算连接这n个城市所需路线长度总和的最小值分析:直接运用kruskal算法求解。这题关键是建图。好好感受下面建图的思想。一开始我还是想按照以前最短路径那样建图,发现cmp的时候就出问题了。嗨,自己弱爆了。View Code 1 // I'm the Topcoder 2 //C 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 #include <ctype.h> 7 #include <math.h> 8 # 阅读全文
posted @ 2013-03-25 09:38 南下的小程序员 阅读(280) 评论(0) 推荐(0) 编辑
摘要: 题意:求从经济人散布谣言到所有人需要的最短时间的最大值具体详解看我原来的解法http://blog.sina.com.cn/s/blog_99ca2df50101807p.htmlView Code 1 // I'm the Topcoder 2 //C 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 #include <ctype.h> 7 #include <math.h> 8 #include <time.h> 9 //C+ 阅读全文
posted @ 2013-03-25 01:32 南下的小程序员 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 记住一定要初始化dis[][],因为这边wa了几次。题意:求起点1到终点n不被抓的概率。也就是要是输出 的结果最大。只要把floyd状态方程改为*就行了。如下所示:dis[i][j]=max(dis[i][j],dis[i][k]*dis[k][j]).切记初始化dis[i][j]=0;要求最大则初始化为-INF 或者0.不能是INFView Code 1 // I'm the Topcoder 2 //C 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 #incl 阅读全文
posted @ 2013-03-25 00:42 南下的小程序员 阅读(218) 评论(0) 推荐(0) 编辑