摘要: 题意:有两只青蛙,a在第一个石头,b在第二个石头,a要到b那里去,每种a到b的路径中都有最大边,求所有这些最大边的最小值。思路:将所有边长存起来,排好序后,二分枚举答案。 时间复杂度比较高,344ms。#include #include #include #include #include using namespace std;const int maxn=210;const int INF=0x3f3f3f3f;double w[maxn][maxn]; //存储边长double wlen[30000];int con[maxn][maxn]; //con[i][j]=1表示i、j连通,. 阅读全文
posted @ 2013-10-17 15:22 辰曦~文若 阅读(321) 评论(0) 推荐(0)
摘要: 用的是prim算法。我用vector数组,每次求最小的dis时,不需要遍历所有的点,只需要遍历之前加入到vector数组中的点(即dis[v]!=INF的点)。但其实时间也差不多,和遍历所有的点的方法都是16ms。。。#include #include #include #include #include #include using namespace std;const int INF=0x3f3f3f3f;int n,cost;int ans;int w[101][101];int dis[101]; //生成树外的点与生成树相连的最短边长int pre[101]; //pre[v]为v 阅读全文
posted @ 2013-10-17 09:43 辰曦~文若 阅读(230) 评论(0) 推荐(0)
摘要: 题意:给出邻接矩阵,在给出q条已经建好的路,让你再建一些路,使得连通所有的村庄并且兴建的路的长度时最小的。思路:1.可以先将建好的路的端点合并,这里要注意的是,首先先要判断两个端点u、v的根节点是否相同,不同的话在合并。是为了防止有重复或者有环出现。 2.可以将建好的路的cost设为0,再直接用kruskal算法。由于建边的时候是用了上三角矩阵,所以很容易用端点u、v来推出相应边的编号。代码1:#include #include #include #include #include using namespace std;int n,q,cost,index,a,b;int ans;struc 阅读全文
posted @ 2013-10-17 09:01 辰曦~文若 阅读(213) 评论(0) 推荐(0)