摘要: 记得在哪里做过一遍,最简单的最小生成树,直接用kruskal秒掉了。代码如下: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #define LEN 110 8 using namespace std; 9 10 typedef struct {11 double x, y;12 }POINT;13 14 POINT Point[LEN];15 16 typedef struct {17 int a, b;18 double w;19 }ARC;20 21 ARC Ar... 阅读全文
posted @ 2013-11-24 23:11 张小豪 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 这道题的大致意思是给你一个有20个点的无向图,再给你最多100个查询。让你每次查询输出两个顶点之间的最短路径长度。本题是最基础的图论题,解决方法有多种,下面我们列举若干种方法并结合其效率进行讨论:一、简单BFS 这种算法是最基本的算法,对于任意两个点直接用广度优先搜索惊醒最短路径求解。写起来方便但是效率并不怎么高。代码如下: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #define LEN 3011 using nam... 阅读全文
posted @ 2013-11-24 20:56 张小豪 阅读(285) 评论(0) 推荐(0) 编辑
摘要: n个人报数找到只有一个报过且最小的数。代码如下: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #define INF 0x7fffffff 8 #define LEN 1000100 9 using namespace std;10 11 struct P{12 char name[50];13 int num;14 }man[LEN];15 16 bool cmp(struct P a, struct P b){17 return a.num<b.num;18 }1... 阅读全文
posted @ 2013-11-24 15:50 张小豪 阅读(158) 评论(0) 推荐(0) 编辑