91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 18KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-24
  • 語言: 其他
  • 標簽: 數據結構??

資源簡介

n個村莊之間的交通圖用有向加權圖表示,圖中的有向邊表示第i個村莊和第j個村莊之間有道路,邊上的權表示這條道路的長度。現在要從這n個村莊中選擇一個村莊建一所醫院,問這所醫院應建在哪個村莊,才能使離醫院最遠的村莊到醫院最近。

資源截圖

代碼片段和文件信息

#include
#define?MaxInt?10000//最大數?
using?namespace?std;
const?int?MaxNumEdges=50;?
const?int?MaxNumVertices=10;?//最大頂點數?
class?Graph
{
????private:
????????int?vNum;//當前頂點數
????????int?eNum;//當前邊數
????????int?Vertex[MaxNumVertices];//頂點數組
????????int?Edge[MaxNumVertices][MaxNumVertices];//邊數組
????????bool?GetVertexPos(const?int?&vertexint?&i);//給出頂點vertex在圖中的位置
????public:
????????Graph(const?int?sz=?MaxNumEdges);//構造函數
????????bool?FindVertex(const?int?&vertex);
????????bool?InsertVertex(const?int?&?vertex);//插入一個頂點vertex
????????bool?InsertEdge(const?int?v1const?int?v2const?int?weight);//插入一條邊(v1v2)該邊上的權值為weight
????????void?Hospital();//醫院選址函數
};?
Graph::Graph(const?int?sz):?vNum(0)?eNum(0)
//構造函數
{?
????int?ne;
????int?nametailhead;
????int?weight;
????for(int?i=0;i????for(int?j=0;j????{
????????if(i==j)
????????????Edge[i][j]=0;//頂點到自身權值為0
????????else
????????????Edge[i][j]=10000;//鄰接矩陣初始化為最大值
????}
????printf(“請輸入頂點數注意本程序最多為10個!\n“);
????scanf(“%d“&n);
????printf(“請依次輸入頂點名稱:\n“);
????for(int?i=0;i????{
????????scanf(“%d“&name);
????????InsertVertex(name);
????vNum++;
????}
????printf(“請輸入邊數:\n“);
????scanf(“%d“&e);
????printf(“以下輸入邊信息:\n“);
????for(int?i=0;i????{
????????printf(“請輸入第%d邊頭頂點:“i+1);
????????scanf(“%d“&head);
????????printf(“請輸入該邊尾頂點:“);
????????scanf(“%d“&tail);
????????printf(“請輸入該邊權值:“);
????????scanf(“%d“&weight);
????????if(!InsertEdge(headtailweight))
????????{
????????????printf(“不存在該邊,請重輸!\n“);
????????????continue;
????????}
????}
}?
bool?Graph::FindVertex(const?int&?vertex)
//給出頂點vertex在圖中的位置
{
????for?(int?i?=?0;?i?????if?(vertex?==?Vertex[i])
????????return?true;
????return?false;
}?
bool?Graph::?GetVertexPos(const?int?&vertexint?&i)
//給出頂點vertex在圖中的位置
{
????for?(i?=?0;?i?????if?(vertex?==?Vertex[i])
????????return?true;
????return?false;
}?
bool?Graph::InsertVertex(const?int?&?vertex)
//插入一個頂點vertex
{
????if?(FindVertex(vertex))
????????return?false;
????Vertex[vNum]?=?vertex;
????return?true;
}?

bool?Graph::InsertEdge(const?int?v1const?int?v2const?int?weight)
//插入一條邊(v1v2)該邊上的權值為weight
{?
????int?k=0j=0;
????if(GetVertexPos(v1k)?&&?GetVertexPos(v2j))
????{
????????Edge[k][j]=weight;
????????eNum++;
????????Edge[j][k]=weight;
????????eNum++;
????????return?true;
????}
????else
????????return?false;
}?
void?Graph::Hospital()?
//在以鄰接帶權矩陣表示的n個村莊中,求醫院建在何處,使離醫院最遠的村莊到醫院的路徑最短。?
{
????int?kijs;
????for?(k=0;k????????for?(i=0;i????????????for?(j=0;j????????????????if?(Edge[i][k]+Edge[k][j]????????????????????Edge[i][j]=Edge[i][k]+Edge[k][j];
????int?m=MaxInt;?//設定m為機器內最大整數。
????printf(“********************************************\n“);
????//以下為求各村離醫院最近的醫院選址
????int?min=MaxInt?;?//設定機器最大數作村莊間距離之和的初值。
????k=0;?//k設醫院位置。
????for?(j=0;j

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件?????124928??2009-06-08?17:24??大型作業_醫院選址問題.doc

?????文件???????3927??2009-05-18?15:20??大型作業_醫院選址問題.c

-----------?---------??----------?-----??----

???????????????128855????????????????????2


評論

共有 條評論