`
pleasetojava
  • 浏览: 703390 次
  • 性别: Icon_minigender_2
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论
文章列表
每对顶点间的最短距离 稀疏有向图Johnson算法 C++实现 // 稀疏有向图Johnson算法.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<iostream> #define Infinity 65535 #define MAX 100 using namespace std; //边尾节点结构体 struct edgeNode { int no;//节点序号 int weight; //此边权值 ...
// 每对顶点间的最短距离Floyd_Warshall算法.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<iostream> #define MAX 100 #define Infinity 65535 #define NIL 65535 using namespace std; //d int d1[MAX][MAX]; int d2[MAX][MAX]; //用来存储边的权值,即有向图的邻接矩阵 i ...
// 每对顶点间的最短路径.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<iostream> #define MAX 100 #define Infinity 65535 using namespace std; //L2[i][j]存储L1[i][j]*Lij int L1[MAX][MAX]; int L2[MAX][MAX]; //用来存储边的权值,即有向图的邻接矩阵 int w[MAX][MAX] ...
// 每对顶点间的最短路径.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<iostream> #define MAX 100 #define Infinity 65535 using namespace std; // int L1[MAX][MAX]; int L2[MAX][MAX]; //用来存储边的权值,即有向图的邻接矩阵 int w[MAX][MAX]; //初始化,把w[i][j]赋给L1[i] ...
ACM食物链 Description 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。 有人用两种说法对这N个动物所构成的食物链关系进行描述: 第一种说法是"1 X Y",表示X和Y是同类。 第二种说法是"2 X Y",表示X吃Y。 此人对N个动物,用上述两种说法,一句接一句地说出K句话,这K句话有的是真的,有的是假的。当一句话满足下列三条之一时,这句话就是假话,否则就是真话。 1) 当前的话与前面的某 ...
ACM黑箱子 Description 有一个黑箱子,里面会按升序存储整数,你可以对黑箱子下达下面的指令: a. ADD n 将n加入黑箱子 b. Get 获得一个数,这个数在黑箱子里的序号(从0开始计数)是Get的出现次数。 黑箱子中最初存了一个数0,现给你一个操作序列,要你输出Get命令时获的那个数。 输入: 每行是一个命令,如果命令是”ADD”,则后面空一格,有一个整数。输入时保证GET命令不会越界 输出: 每行输出一个整数,整数为对应Get获得值。 Sample Input ADD 3 GET ADD 1 GET ADD -4 ADD 2 ADD 8 ...
差分约束:线性规划矩阵A的每一行包含一个1与一个-1,其他元素为0.因此,由Ax<=b给出的约束条件是m个差分约束集合,其中包含n个未知元。每个约束条件为不等式: xj-xi<=bk 其中1<=i,j<=n,i<=k<=m 解决方法:把n个未知元看成n的有向图的顶点,xj-xi<=bk表示顶点j到顶点i长度为bk的有向线段。再添加一个v0顶点,与v0到其余顶点的有向线段,长度为0。(如下图) 可以证明 xi=β(v0,vi)(β(v0,vi)为顶点0到顶点i的最短路径长度)。所以就可以利用Bellman_Ford算求单源最短路径(不能用Di ...
// 单源最短路径Bellman_Ford算法.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<iostream> #define MAX 100 #define Infinity 65535 typedef int WeiType; using namespace std; struct edgeNode { int no; //边尾端的序号 char info; //边端的名称 WeiType wei ...
// 单源最短路径Dijkstra算法实现.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<iostream> #define MAX 200 #define Infinity 65535 using namespace std; //边尾节点信息结构体 struct edgeNode { int no; //尾接点序号 int cost; //边权值 edgeNode *next; //其下一条邻接边尾 ...
ACM唯一的最小生成树 Description 求一个非负权边的无向连通图的最小生成树,如果这个无向图存在两个或两个以上的最小生成树,就输出Not Unique,否则输出最小生成树的边的权值和。 输入: 第一行是一个整数K,表示有多少个测试用例,以后每个测试用例占m+1行。每个测试用例的第一行为两个整数n,m(3<=n<=100),表示图的顶点数和边数,从第二行开始每行为三个整数i,j,w,表示从i到j顶点的权值。 输出: 每行输出一个测试用例的结果。如果这个无向图存在两个或两个以上的最小生成树,就输出Not Unique,否则输出最小生成树的边的权值和。 Samp ...
// Prim算法实现(采用邻接表存储).cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "stdafx.h" #include<iostream> #define MAX 100 #define Infinity 65535 typedef int WeiType; using namespace std; struct edgeNode { int no; //边端的序号 char i ...
// Kruskal算法实现.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<iostream> #define MAX 100 typedef int WeiType; using namespace std; // struct Edge { int no; //边的序号 int x; //端点1序号 int y; // 端点2序号 WeiType weight; //权值 bool select ...
// 强连通分支(邻接表存储).cpp : Defines the entry point for the console application. //通过二次利用深度优先搜索访问节点,每次的深度优先搜索操作不同 #include "stdafx.h" #include<iostream> #define MAX 100 using namespace std; //深度搜索访问节点层次标志枚举变量 enum Color{white,gray,black}; //边端点结构体 struct edgeNode { int no; //边尾 ...
// 有向无回路图拓扑排序.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<iostream> #define MAX 100 using namespace std; enum Color{white,gray,black}; struct edgeNode { int no; //边尾端的序号 char info; //边端的名称 struct edgeNode * next; //下一个 }; str ...
// 无向图的一节点到另一节点的最短路径(边数最少的路径)(采用邻接表存储).cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<iostream> #define MAX 100 #define MAXQ 50 using namespace std; struct edgeNode { int no; //边端的序号 char info; //边端的名称 struct edgeNode * next; //下一 ...
Global site tag (gtag.js) - Google Analytics