范文无忧网公文文书入党入团

用Prim算法的基本思想求解吃所有的最小生成树并给出求解过程的动

02月10日 编辑 fanwen51.com

[求计算机图形学中的直线绘制函数法 DDA算法中点法和]Bresenham算法的特点是: 1,不必计算直线之斜率,因此不做除法; 2,不用浮点数,只用整数; 3,只做整数加减法和乘2运算,而乘2运算可以用硬件移位实现. Bresenham算法速度很快,并适于用硬件...+阅读

看看这个相似的吧: #include #include using namespace std; #define BUFSIZE 555 #define ULTIMATE 2000000000 struct Node{ int parent; int key; }node[BUFSIZE]; int N,M; int Graph[BUFSIZE][BUFSIZE]; void init() { fill_n(&Graph[0][0],BUFSIZE*BUFSIZE,ULTIMATE); scanf( "%d%d ",&N,&M); for(int i=1;i int s,d,v; scanf( "%d%d%d ",&s,&d,&v); Graph[s][d] = v; Graph[d][s] = v; } } bool comp(Node a,Node b) { if(a.key){ if(b.key) return a.key else return true; } return false; } void prim() { SUM = 0; for(int j=1;j node[j].parent = N; node[j].key = Graph[N][j]; } node[N].key = 0; for(int i=1;i Node *p = min_element(node+1,node+1+N,comp); int k = p - node; p->key = 0; //表示点p已经加入了生成树的集合。

for(int j=1;j if(Graph[k][j] node[j].parent = k; node[j].key = Graph[k][j]; } } } 修改 删除 举报 引用 回复 加为好友 发送私信 在线聊天 wwq_vista 等级: 发表于:2007-07-11 21:20:042楼 得分:0 必须按严格按要求做啊,提出的要求全部要实现、、、、由于本人平时没有认真学习加之时间紧迫,不得以而发贴求问啊。请高手帮忙,在下先谢过。 修改 删除 举报 引用 回复 加为好友 发送私信 在线聊天 pkurao pkurao 等级: 发表于:2007-07-22 10:51:553楼 得分:5 好像我另外一块硬盘上有写过,还经过测试的,给我发email我如果还在 就给你发过去pkurao126.om 修改 删除 举报 引用 回复 加为好友 发送私信 在线聊天 trueytht 一碗阳春面 等级: 发表于:2007-08-02 20:38:414楼 得分:80 我在vs2005下写了一个,经过测试完全满足你的要求. 一共两个project : 一个Graph 还有一个UnDiGraph. 其中Graph project下有3个文件Edge.h, Vertex.h, Graph.h.里面分别是 边类,顶点类和图类. 而UnDiGraph project下只有一个文件夹UnDiGraph.h,里面是UnDiGraph类的定义. 其中 类UnDiGraph 继承自 类Graph. 我是用模板写的,由于编译器不支持类模板的分离编译,所以除了main所在的文件以外,没有.cpp文件.全放在了.h文件中实现. 另外,输入输出我都截图了,可惜发现无法发上来. 修改 删除 举报 引用 回复 加为好友 发送私信 在线聊天 trueytht 一碗阳春面 等级: 发表于:2007-08-02 20:39:215楼 得分:0 /*************** Graph Project *********************/ // Edge.h #ifndef EDGE_H #define EDGE_H #include using namespace std; template class Edge { public: Edge(int dest, DistType cost) { //constructor this->dest = dets; this->cost = cost; this->link = NULL; } Edge(int dest, DistType cost, Edge *link) { //constructor this->dest = dest; this->cost = cost; this->link = link; } int getDest(void) const { return dest; } DistType getCost(void) const { return cost; } Edge * getLink(void) const { return link; } void setDest(int dest) { this->dest = dest; } void setCost(DistType cost) { this->cost = cost; } void setLink(Edge *p) { this->link = p; } private: int dest; DistType cost; Edge *link; }; #endif //Vertex.h #ifndef VERTEX_H #define VERTEX_H #include "Edge.h " template class Vertex { public: Vertex(void) { this->adj = NULL; } Vertex(NameType data) { this->data = data; this->adj = NULL; } NameType getData(void) const { return data; } Edge * getAdj(void) const { return adj; } void setData(NameType data) { this->data = data; } void setAdj(Edge *adj) { this->adj = adj; } private: NameType data; Edge *adj; }; #endif // Graph.h #ifndef GRAPH_H #define GRAPH_H #include "Vertex.h " template class Graph { public: Graph(int maxnum, int n ,int e):maxNumVertices(maxnum), numVertices(n), numEdges(e) { // constructor NameType name; nodeTable = new Vertex [maxNumVertices]; // partly intialize, cannot initialize nodeTable within derived class for (int i = 0; i cout cin >>name; nodeTable[i].setData(name); nodeTable[i].setAdj(NULL); } } Graph(const Graph &otherGraph) { // copy constructor numVertices = otherGraph.getNumVertices(); numEdges = otherGraph.getNumEdges(); nodeTable = new Vertex [numVertices]; // partly intialize, cannot initialize nodeTable within derived class for (int i = 0; i nodeTable[i].setData(otherGraph.getVertexValue(i)); nodeTable[i].setAdj(NULL); } } Graph & operator =(const Graph &otherGraph) { // = if (this != &otherGraph) { for (int i = 0; i for (Edge *p = nodeTable[i].getAdj(); p != NULL; p = nodeTable[i].getAdj()) { nodeTable[i].setAdj(p->getLink()); delete p; } } delete []nodeTable; numVertices = 0; numEdges = 0; numVertices = otherGraph.getNumVertices(); numEdges = otherGraph.getNumEdges(); nodeTable = new Vertex [numVertices]; // partly intialize for (int i = 0; i nodeTable[i].setData(otherGraph.getVertexValue(i)); nodeTable[i].setAdj(NULL); } } return *this; } virtual ~Graph(void) { // destructor for (int i = 0; i for (Edge *p = nodeTable[i].getAdj(); p != NULL; p = nodeTable[i].getAdj()) { nodeTable[i].setAdj(p->getLink()); delete p; } } numVertices = 0; numEdges = 0; ...

延伸阅读:

利用C语言编写能够画出任意斜率的直线算法程序利用中点画线法改将DDA算法改成中点划线算法即可// DDA画线View.cpp : implementation of the CDDAView class//#include "stdafx.h"#include "DDA画线.h"#include "DDA画线Doc.h"#include "DDA画线...

求解合同法教程试题一、该案例其实法律关系简单,只是涉及的一方是县政府而已,县政府在此中充当普通民事主体角色,并不是行政合同。被告乙违法合同约定,应带承担违约责任,违约责任的性质只是单纯的民...

公司法案例分析答案求解1、公司法中规定,有限责任公司的最低法定注册资本为3万元,案例中,公司章程中规定公司的注册资本为60万元,大于法定资本的最低限额,所以该项合法。 2、案例中,公司章程关于公司组织...

根据预算法的规定国务院应当及时下达关于编制下一年度预算方预算的审批 一、下达和上报 国务院于每年11月10日前向省、自治区、直辖市政府和中央各部门下达编制下一年度预算草案的指示,提出编制预算草案的原则和要求。 财政部根据国务...

求解答!冷餐会就餐有什么礼仪呢Hello, boys and girls! 你们吃过西餐吗?你们告诉英国人的用餐礼仪吗?请随我一起网页一下吧! 就座时,身体(body)要端正,手肘(elbow)不要放到桌面上,不能翘足(foot),与餐桌的距离以便于用于...

姐姐按照预算法编制医院的预算模版你有吗我没有模版。下面编制思路供你参考吧。 医院收入预算的编制 医院收入预算的编制,应参考上年度实际收入水平,结合预算年度医院事业发展和工作任务计划,以及医疗收费标准等因素确...

通过MATLAB遗传算法的思想来解决fx x sin10pi x 2首先在matlab命令窗口输入f=(x)-(x*sin(10*pi*x)+2) 输出结果为 >> f=(x)-(x*sin(10*pi*x)+2) f = (x)-(x*sin(10*pi*x)+2) 接着输入gatool会打开遗传算法工具箱 按上图所示...

求解合同法试题我认为商场无权要求刘某返还随身听或补足差价,只能向售货员追偿损失。理由: 一、首先,刘某不属于不当得利,构成不当得利的一个条件是“受益人取得利益没有合法根据,即既没有法律...

进口车关税怎么算法律知识大全中国加入WTO后,逐年减让进口汽车的关税,目前小轿车进口关税为25%加17%增值税,另外根据车辆的排量加消费税。 排气量在1.0升以下(含1.0升)的 1% 排气量在1.0升以上至1.5升(含1.5升)...

推荐阅读
图文推荐
栏目列表