摘要: 题意一只母牛从N块田中的任一块(1≤N≤1000)去参加盛大的母牛聚会,这个聚会被安排在X号田(1≤X ≤N)。一共有M(1 ≤ M ≤ 100,000)条单行道分别连接着两块田,且通过路i需要花Ti(1≤Ti≤100)的时间。每头母牛必需参加宴会并且在宴会结束时回到自己的领地,但是每头牛都很懒而喜欢选择化是最少的一个方案。来时的路和去时的可能不一样。求每头牛要来回的最短时间。思路:正着求一次最短路径,矩阵转置,再求一次最短路径,想加求最大#include <iostream>#include <string.h>using namespace std;const in 阅读全文
posted @ 2011-04-21 15:55 L.. 阅读(222) 评论(0) 推荐(0) 编辑
摘要: dijkstra SSIP#include <stdio.h>#include <string.h>#include <stdlib.h>using namespace std;const int MAXN = 101;const int MAXINT = 32767;int G[MAXN][MAXN];bool used[MAXN];int pre[MAXN];int dist[MAXN]; void dijkstra(int n){ for(int i = 1; i <= n; i++){ dist[i] = G[1][i]; used[i] = 阅读全文
posted @ 2011-04-21 15:26 L.. 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 给你n个人的联系情况,对任意一个人,求出这个人发消息到其他n-1个人的时间,得到n-1个时间中的最大值,n个最大值中的最小值就是所求。如果网络不通,那就输出disjointFloyed算出任意两个人的最小时间 就OK了#include <iostream>#include <fstream>using namespace std;const int MAXN = 101;const int INF = 0x7FFF;int m , n;int G[MAXN][MAXN];void in(){ int i,j,w,t; for(i = 1; i <= m;i++) 阅读全文
posted @ 2011-04-21 14:33 L.. 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 并查集+set容器 Kruskal#include <stdio.h>#include <string.h>#include <set>using namespace std;const int MAXN = 501;struct E{ int x,y; int weight;};E edge[25001];int father[MAXN];int cmp(const void *d1,const void *d2){ return (*(E*)d1).weight - (*(E*)d2).weight;}void makeSet(int n){ for(i 阅读全文
posted @ 2011-04-21 14:20 L.. 阅读(277) 评论(0) 推荐(0) 编辑
摘要: 基础 Kruskal#include <iostream>#include <stdio.h>using namespace std;const int MAXN = 101;struct E{ int x,y; int weight;};E edge[MAXN*MAXN/2];int G[MAXN][MAXN];int father[MAXN];int cmp(const void *d1, const void *d2){ return (*(E*)d1).weight - (*(E*)d2).weight;}void makeSet(int n){ for(int 阅读全文
posted @ 2011-04-21 14:16 L.. 阅读(317) 评论(0) 推荐(0) 编辑
摘要: 读入边权要注意是否比原来的边权小#include <iostream>#include <fstream>#include <string.h>using namespace std;const int MAXN = 1000;int G[MAXN][MAXN];int lowcost[MAXN];int cloest[MAXN];bool used[MAXN];int cost;void PRIM(int n){ int cnt = 0; cost = 0; used[1] = true; for(int i = 2; i <= n; i++){ l 阅读全文
posted @ 2011-04-21 14:11 L.. 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 最小生成树..#include <iostream>#include <string.h>#include <math.h>#include <iomanip>using namespace std;const int MAXN = 101;struct point { double x,y;};point p[MAXN];double G[MAXN][MAXN];double lowcost[MAXN];int closest[MAXN];bool used[MAXN];double cost;void PRIM(int n){ cost = 阅读全文
posted @ 2011-04-21 13:41 L.. 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 基础的最小生成树 有的路已经建好了,就把矩阵置0 就可以了//prim MST#include <stdio.h>#include <stdlib.h>#include <string.h>int G[101][101]; bool used[101]; int lowcost[101];int closest[101];int cost;void prim(int n){ cost = 0; used[1] = true; int minj; for(int i = 2; i <= n; i++){ lowcost[i] = G[i][1]; clo 阅读全文
posted @ 2011-04-21 13:39 L.. 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 并查集 找连通分量 水之#include <stdio.h>int set[1001];int find(int x){ while(set[x] != x) x = set[x]; return x;}void merge(int x,int y){ int fx , fy; fx = find(x); fy = find(y); if(fx != fy){ set[fx] = fy; }}int main(){ int m,n,i,cnt,x,y; while(scanf("%d",&n),n){ for(i = 1; i <= 1000; + 阅读全文
posted @ 2011-04-21 13:15 L.. 阅读(110) 评论(0) 推荐(0) 编辑