摘要: 并查集显然要用到左偏树解决合并的问题这题体现了数据结构的强大啊!#include<stdio.h>#include <algorithm>using namespace std;const int MAXN = 100100;int father[MAXN];struct Monkey{ int l,r; int dis; int strong;}LTree[MAXN];int find(int x){ if(x != father[x]) father[x] = find(father[x]); return father[x];}int merge(int x,in 阅读全文
posted @ 2011-05-01 09:17 L.. 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 参考 算法导论 p580 单终点最短路径问题这两题是一样的求法,先正着求一次最短路,再将边反向,再求一次矩阵表示图的话就是将矩阵转置一次,邻接表表示的话就是读入边的时候,建两个表poj3268dijkstra求最短路#include <iostream>#include <string.h>using namespace std;const int MAXN =1001;int n,m,x;const int INF = 0x7FFF;int G[MAXN][MAXN];int dist1[MAXN];int sum[MAXN];bool used[MAXN];void 阅读全文
posted @ 2011-05-01 01:30 L.. 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 一、Bellman-Ford算法最优性原理它是最优性原理的直接应用,算法基于以下事实:l 如果最短路存在,则每个顶点最多经过一次,因此不超过n-1条边;l 长度为k的路由长度为k-1的路加一条边得到;l 由最优性原理,只需依次考虑长度为1,2,…,k-1的最短路。适用条件&范围l 单源最短路径(从源点s到其它所有顶点v); l 有向图&无向图(无向图可以看作(u,v),(v,u)同属于边集E的有向图); l 边权可正可负(如有负权回路输出错误提示); l 差分约束系统(需要首先构造约束图,构造不等式时>=表示求最小值, 作为最长路,<=表示求最大值, 作为最短路。& 阅读全文
posted @ 2011-04-30 06:40 L.. 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 裸的拓扑排序 图用邻接表表示方法是dfs#include<stdio.h>#include<string.h>const int MAXN = 1000;struct edge{ int u, v, next;}e[MAXN];int n;int first[MAXN], cnt;bool visit[MAXN], f;int sort[MAXN], top;void dfs(int s){ if(visit[s]) return; visit[s] = true; for(int x = first[s]; x != -1; x = e[x].next){ if(!v 阅读全文
posted @ 2011-04-30 06:34 L.. 阅读(240) 评论(0) 推荐(0) 编辑
摘要: 留下代码有空写解题报告 蛋疼的题目#include<stdio.h>const int MAXN = 501;const int INF = 0x3f3f3f3f;int n, m;int map[MAXN][MAXN], dist[MAXN];bool used[MAXN];void dijkstra(){ for(int i = 1; i <= n; ++i){ dist[i] = map[1][i]; used[i] = false; } used[1] = true; dist[1] = 0; for(int i = 1; i < n; ++i){ int mi 阅读全文
posted @ 2011-04-30 05:39 L.. 阅读(299) 评论(0) 推荐(0) 编辑
摘要: where the sum goes over all pairs of types in the derivation plan such that to is the original type and td the type derived from it and d(to,td) is the distance of the types1/Σ(to,td)d(to,td)派生关系有向边,边权为两个串的不同字符的个数,要求的是找出一种用到所有串的派生关系,使得Q最小,(因为是1/Q),所以这题就是求最小生成树 最朴素的最小生成树AC#include<stdio.h>const 阅读全文
posted @ 2011-04-30 01:36 L.. 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 1062*昂贵的聘礼枚举等级限制+dijkstra1087*APlugforUNIX2分匹配1094SortingItAllOutfloyd或拓扑ac!1112*TeamThemUp!2分图染色+DP1125StockbrokerGrapevineFLOYD 1135DominoEffect最短路1149*PIGS网络流1161*Wallsfloyd1201Intervals差分约束1236*NetworkofSchools强联通1251JungleRoadsMST1273DrainageDitches最大流1274ThePerfectStall2分匹配1275*CashierEmployme 阅读全文
posted @ 2011-04-28 05:38 L.. 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 题意一只母牛从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) 编辑