|
|
|
@ -1,351 +0,0 @@
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <conio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
#define ALLNameNum 99
|
|
|
|
|
#define INF 99999
|
|
|
|
|
|
|
|
|
|
typedef int dist[ALLNameNum];
|
|
|
|
|
typedef int path[ALLNameNum];
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
char name[100];
|
|
|
|
|
char intro[999];
|
|
|
|
|
int x, y;
|
|
|
|
|
}SITE;
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
SITE site[ALLNameNum];
|
|
|
|
|
int length[ALLNameNum][ALLNameNum];
|
|
|
|
|
}MAP;
|
|
|
|
|
|
|
|
|
|
MAP M;
|
|
|
|
|
int N = 0;
|
|
|
|
|
path p;
|
|
|
|
|
dist d;
|
|
|
|
|
|
|
|
|
|
void init()
|
|
|
|
|
{
|
|
|
|
|
int i, j;
|
|
|
|
|
strcpy(M.site[1].name, "苹果园");
|
|
|
|
|
strcpy(M.site[1].intro, "北京市石景山区,位于苹果园南路");
|
|
|
|
|
strcpy(M.site[2].name, "古城");
|
|
|
|
|
strcpy(M.site[2].intro, "位于北京市石景山区石景山路与古城小街交会东侧");
|
|
|
|
|
strcpy(M.site[3].name, "八角游乐园");
|
|
|
|
|
strcpy(M.site[3].intro, "石景山区八角立交桥东侧");
|
|
|
|
|
strcpy(M.site[4].name, "公主坟");
|
|
|
|
|
strcpy(M.site[4].intro, "北京市海淀区复兴路和西三环中路交会处下方");
|
|
|
|
|
strcpy(M.site[5].name, "复兴门");
|
|
|
|
|
strcpy(M.site[5].intro, "位于北京市西城区复兴门外大街、复兴门内大街、复兴门南大街、复兴门北大街交汇处");
|
|
|
|
|
strcpy(M.site[6].name, "天安门西");
|
|
|
|
|
strcpy(M.site[6].intro, "位于中国北京市西城区西长安街和南长街交会处,是北京地铁运营有限公司运营管理的车站,也是北京地铁1号线的中间站");
|
|
|
|
|
strcpy(M.site[7].name, "建国门");
|
|
|
|
|
strcpy(M.site[7].intro, "位于中国北京市东城区与朝阳区交界处建国门桥下方,是北京地铁运营有限公司运营的车站,也是北京地铁1号线、北京地铁2号线的换乘站");
|
|
|
|
|
strcpy(M.site[8].name, "永安门");
|
|
|
|
|
strcpy(M.site[8].intro, "位于中国北京市朝阳区建国门外大街与东大桥路交叉口的下方");
|
|
|
|
|
strcpy(M.site[9].name, "鼓楼大街");
|
|
|
|
|
strcpy(M.site[9].intro, "是北京地铁2号线与北京地铁8号线的换乘站,位于北京市西城区与东城区交界处,安定门西大街-德胜门东大街与旧鼓楼大街-旧鼓楼外大街交会处");
|
|
|
|
|
strcpy(M.site[10].name, "雍和宫");
|
|
|
|
|
strcpy(M.site[10].intro, "位于北京市东城区北二环安定门东大街与雍和宫大街、和平里西街交汇处");
|
|
|
|
|
strcpy(M.site[11].name, "朝阳门");
|
|
|
|
|
strcpy(M.site[11].intro, "位于北京市东城区与朝阳区交界处,朝阳门外大街-朝阳门内大街与朝阳门南大街-朝阳门北大街交汇处");
|
|
|
|
|
strcpy(M.site[12].name, "北京站");
|
|
|
|
|
strcpy(M.site[12].intro, "位于中国北京市东城区境内、北京站北广场下方");
|
|
|
|
|
strcpy(M.site[13].name, "崇文门");
|
|
|
|
|
strcpy(M.site[13].intro, "北京地铁2号线和北京地铁5号线在此交汇,位于北京市东城区前门东大街与崇文门内大街交汇口");
|
|
|
|
|
strcpy(M.site[14].name, "和平门");
|
|
|
|
|
strcpy(M.site[14].intro, "位于北京市西城区北新华街-南新华街与前门西大街-宣武门东大街交汇处");
|
|
|
|
|
strcpy(M.site[15].name, "宣武门");
|
|
|
|
|
strcpy(M.site[15].intro, "位于中国北京市西城区,是北京地铁2号线和北京地铁4号线的换乘站");
|
|
|
|
|
strcpy(M.site[16].name, "长椿街");
|
|
|
|
|
strcpy(M.site[16].intro, "长椿街站是北京地铁2号线的一个车站,位于北京市西城区宣武门西大街、长椿街交汇处");
|
|
|
|
|
strcpy(M.site[17].name, "西直门");
|
|
|
|
|
strcpy(M.site[17].intro, "位于北京市西城区西直门桥下方");
|
|
|
|
|
strcpy(M.site[18].name, "圆明园");
|
|
|
|
|
strcpy(M.site[18].intro, "位于北京市海淀区清华西路");
|
|
|
|
|
strcpy(M.site[19].name, "北京大学东门");
|
|
|
|
|
strcpy(M.site[19].intro, "位于中国北京市海淀区境内");
|
|
|
|
|
strcpy(M.site[20].name, "中关村");
|
|
|
|
|
strcpy(M.site[20].intro, "位于北京市海淀区中关村一桥南侧");
|
|
|
|
|
strcpy(M.site[21].name, "海淀黄庄");
|
|
|
|
|
strcpy(M.site[21].intro, "是北京地铁4号线和北京地铁10号线的换乘站");
|
|
|
|
|
strcpy(M.site[22].name, "人民大学");
|
|
|
|
|
strcpy(M.site[22].intro, "位于北京市海淀区四通桥");
|
|
|
|
|
strcpy(M.site[23].name, "国家图书馆");
|
|
|
|
|
strcpy(M.site[23].intro, "国家图书馆站位于国家图书馆的南侧地下");
|
|
|
|
|
strcpy(M.site[24].name, "动物园");
|
|
|
|
|
strcpy(M.site[24].intro, "位于北京市西直门外大街");
|
|
|
|
|
strcpy(M.site[25].name, "北京南站");
|
|
|
|
|
strcpy(M.site[25].intro, "位于中国北京市丰台区铁路北京南站下方");
|
|
|
|
|
strcpy(M.site[26].name, "西红门");
|
|
|
|
|
strcpy(M.site[26].intro, "位于中国北京市大兴区境内");
|
|
|
|
|
strcpy(M.site[27].name, "生物医药基地");
|
|
|
|
|
strcpy(M.site[27].intro, "是北京地铁4号线的一座车站,位于北京市大兴区新源大街与永大路交口南侧");
|
|
|
|
|
strcpy(M.site[28].name, "天坛东门");
|
|
|
|
|
strcpy(M.site[28].intro, "位于中国北京市东城区");
|
|
|
|
|
strcpy(M.site[29].name, "天通苑");
|
|
|
|
|
strcpy(M.site[29].intro, "是北京地铁5号线的一座车站,也是北京第一个通过民意增加的地铁车站,位于北京市昌平区立汤路与太平庄中二街交汇处北侧");
|
|
|
|
|
strcpy(M.site[30].name, "天通苑北");
|
|
|
|
|
strcpy(M.site[30].intro, "位于北京市昌平区天通苑北界太平庄北街以北400米处");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 1; i <= ALLNameNum; i++)
|
|
|
|
|
{
|
|
|
|
|
for (j = 1; j <= ALLNameNum; j++)
|
|
|
|
|
{
|
|
|
|
|
M.length[i][j] = INF;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (i = 1; i <= ALLNameNum; i++)
|
|
|
|
|
M.length[i][i] = 0;
|
|
|
|
|
M.length[1][2] = M.length[2][1] = 30;
|
|
|
|
|
M.length[1][3] = M.length[3][1] = 30;
|
|
|
|
|
M.length[2][3] = M.length[3][2] = 90;
|
|
|
|
|
M.length[2][4] = M.length[4][2] = 70;
|
|
|
|
|
M.length[3][5] = M.length[5][3] = 50;
|
|
|
|
|
M.length[3][6] = M.length[6][3] = 50;
|
|
|
|
|
M.length[4][5] = M.length[5][4] = 50;
|
|
|
|
|
M.length[4][7] = M.length[7][4] = 100;
|
|
|
|
|
M.length[5][6] = M.length[6][5] = 30;
|
|
|
|
|
M.length[6][7] = M.length[7][6] = 110;
|
|
|
|
|
M.length[6][10] = M.length[10][6] = 20;
|
|
|
|
|
M.length[7][8] = M.length[8][7] = 30;
|
|
|
|
|
M.length[7][9] = M.length[9][7] = 30;
|
|
|
|
|
M.length[7][10] = M.length[10][7] = 30;
|
|
|
|
|
M.length[8][9] = M.length[9][8] = 30;
|
|
|
|
|
M.length[9][10] = M.length[10][9] = 60;
|
|
|
|
|
M.length[9][11] = M.length[11][9] = 40;
|
|
|
|
|
M.length[10][11] = M.length[11][10] = 40;
|
|
|
|
|
M.length[11][12] = M.length[12][11] = 100;
|
|
|
|
|
M.length[11][13] = M.length[13][11] = 50;
|
|
|
|
|
M.length[12][13] = M.length[13][12] = 60;
|
|
|
|
|
M.length[12][15] = M.length[15][12] = 30;
|
|
|
|
|
M.length[12][17] = M.length[17][12] = 170;
|
|
|
|
|
M.length[13][14] = M.length[14][13] = 70;
|
|
|
|
|
M.length[13][15] = M.length[15][13] = 30;
|
|
|
|
|
M.length[13][16] = M.length[16][13] = 50;
|
|
|
|
|
M.length[14][16] = M.length[16][14] = 50;
|
|
|
|
|
M.length[15][16] = M.length[16][15] = 20;
|
|
|
|
|
M.length[16][17] = M.length[17][16] = 30;
|
|
|
|
|
M.length[17][18] = M.length[18][17] = 60;
|
|
|
|
|
M.length[17][19] = M.length[19][17] = 30;
|
|
|
|
|
M.length[17][20] = M.length[20][17] = 170;
|
|
|
|
|
M.length[18][20] = M.length[20][18] = 70;
|
|
|
|
|
M.length[19][21] = M.length[21][19] = 30;
|
|
|
|
|
M.length[20][21] = M.length[21][20] = 50;
|
|
|
|
|
M.length[21][22] = M.length[22][21] = 50;
|
|
|
|
|
M.length[21][24] = M.length[24][21] = 20;
|
|
|
|
|
M.length[22][23] = M.length[23][22] = 30;
|
|
|
|
|
M.length[23][25] = M.length[25][23] = 60;
|
|
|
|
|
M.length[23][26] = M.length[26][23] = 30;
|
|
|
|
|
M.length[24][25] = M.length[25][24] = 170;
|
|
|
|
|
M.length[25][27] = M.length[27][25] = 70;
|
|
|
|
|
M.length[26][27] = M.length[27][26] = 30;
|
|
|
|
|
M.length[27][28] = M.length[28][27] = 50;
|
|
|
|
|
M.length[27][29] = M.length[29][27] = 50;
|
|
|
|
|
M.length[28][29] = M.length[29][28] = 20;
|
|
|
|
|
M.length[29][30] = M.length[30][29] = 30;
|
|
|
|
|
N = 30;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void queryAllSite()
|
|
|
|
|
{
|
|
|
|
|
int t;
|
|
|
|
|
printf("所有地点如下:\n");
|
|
|
|
|
for (t = 1; t <= N; t++)
|
|
|
|
|
{
|
|
|
|
|
printf("编号; %d\n 地点:%s\n 介绍:%s\n", t, M.site[t].name, M.site[t].intro);
|
|
|
|
|
}
|
|
|
|
|
printf("\n任意键返回");
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void querySite()
|
|
|
|
|
{
|
|
|
|
|
int a;
|
|
|
|
|
printf("请问您要查询的地点编号是:");
|
|
|
|
|
scanf("%d", &a);
|
|
|
|
|
if (a > N)
|
|
|
|
|
printf("查询的地点不存在,查询失败!");
|
|
|
|
|
else
|
|
|
|
|
printf("编号:%d\n 地点:%s\n 介绍:%s\n", a, M.site[a].name, M.site[a].intro);
|
|
|
|
|
printf("\n按任意键返回!");
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dijkstraAllSite()
|
|
|
|
|
{
|
|
|
|
|
int v0;
|
|
|
|
|
printf("请输入查询的地点:");
|
|
|
|
|
scanf("%d", &v0);
|
|
|
|
|
bool flag[ALLNameNum];
|
|
|
|
|
//v表示上一个节点,k表示遍历节点
|
|
|
|
|
int i, k, j, v, min, x;
|
|
|
|
|
for (v = 1; v <= N; v++)
|
|
|
|
|
{
|
|
|
|
|
flag[v]=0;
|
|
|
|
|
d[v] = M.length[v0][v];
|
|
|
|
|
if (d[v] < INF && d[v] != 0)
|
|
|
|
|
p[v] = v0;
|
|
|
|
|
else
|
|
|
|
|
p[v] = -1;
|
|
|
|
|
}
|
|
|
|
|
flag[v0] = 1;
|
|
|
|
|
d[v0] = 0;//原点距离
|
|
|
|
|
for (i = 2; i <= N; i++)
|
|
|
|
|
{
|
|
|
|
|
min = INF;
|
|
|
|
|
for (k = 1; k <= N; ++k)
|
|
|
|
|
if (!flag[k] && d[k] < min)
|
|
|
|
|
{//没有被查询过并且距离小于最小值则更新
|
|
|
|
|
v = k;
|
|
|
|
|
min = d[k];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (min == INF)
|
|
|
|
|
return;
|
|
|
|
|
flag[v] = 1;
|
|
|
|
|
for (k = 1; k <= N; ++k)
|
|
|
|
|
if (!flag[k] && (min + M.length[v][k] < d[k]))
|
|
|
|
|
{
|
|
|
|
|
d[k] = min + M.length[v][k];//到k的距离
|
|
|
|
|
p[k] = v;//k节点的上一个节点是v
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void printAllSite()
|
|
|
|
|
{
|
|
|
|
|
int st[ALLNameNum], i, pre, top = -1;
|
|
|
|
|
for (i = 1; i <= N; i++)
|
|
|
|
|
{
|
|
|
|
|
printf("\n到达地点%2d的总距离为: %5d , 经过路径为:", i, d[i]);
|
|
|
|
|
st[++top] = i;
|
|
|
|
|
pre = p[i];
|
|
|
|
|
while (pre != -1)
|
|
|
|
|
{
|
|
|
|
|
st[++top] = pre;
|
|
|
|
|
pre = p[pre];
|
|
|
|
|
}
|
|
|
|
|
while (top > 0)
|
|
|
|
|
{
|
|
|
|
|
printf("%d", st[top--]);
|
|
|
|
|
if (top > 0)
|
|
|
|
|
printf("--->");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dijkstraTwoSite()
|
|
|
|
|
{
|
|
|
|
|
int v0;
|
|
|
|
|
printf("请输入起始地点所对应的编号:");
|
|
|
|
|
scanf("%d", &v0);
|
|
|
|
|
bool flag[ALLNameNum];
|
|
|
|
|
int i, k, j, v, min, x;
|
|
|
|
|
for (v = 1; v <= N; v++)
|
|
|
|
|
{
|
|
|
|
|
flag[v] = 0;
|
|
|
|
|
d[v] = M.length[v0][v];
|
|
|
|
|
if (d[v] < INF && d[v] != 0)
|
|
|
|
|
p[v] = v0;
|
|
|
|
|
else
|
|
|
|
|
p[v] = -1;
|
|
|
|
|
}
|
|
|
|
|
flag[v0] = 1;
|
|
|
|
|
d[v0] = 0;
|
|
|
|
|
for (i = 2; i <= N; i++)
|
|
|
|
|
{
|
|
|
|
|
min = INF;
|
|
|
|
|
for (k = 1; k <= N; ++k)
|
|
|
|
|
if (!flag[k] && d[k] < min)
|
|
|
|
|
{
|
|
|
|
|
v = k;
|
|
|
|
|
min = d[k];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (min == INF)
|
|
|
|
|
return;
|
|
|
|
|
flag[v] = 1;
|
|
|
|
|
for (k = 1; k <= N; ++k)
|
|
|
|
|
if (!flag[k] && (min + M.length[v][k] < d[k]))
|
|
|
|
|
{
|
|
|
|
|
d[k] = min + M.length[v][k];
|
|
|
|
|
p[k] = v;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void printTwoSite()
|
|
|
|
|
{
|
|
|
|
|
int y;
|
|
|
|
|
printf("\n请输入目的地点所对应的编号:");
|
|
|
|
|
scanf("%d", &y);
|
|
|
|
|
int st[ALLNameNum], i, pre, top = -1;
|
|
|
|
|
for (i = 1; i <= N; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i == y)
|
|
|
|
|
printf("\n总距离是: %5d , 经过路径为:", d[i]);
|
|
|
|
|
st[++top] = i;
|
|
|
|
|
pre = p[i];
|
|
|
|
|
while (pre != -1)
|
|
|
|
|
{
|
|
|
|
|
st[++top] = pre;
|
|
|
|
|
pre = p[pre];
|
|
|
|
|
}
|
|
|
|
|
while (top > 0)
|
|
|
|
|
{
|
|
|
|
|
if (i == y)
|
|
|
|
|
{
|
|
|
|
|
printf("%d", st[top--]);
|
|
|
|
|
if (top > 0)
|
|
|
|
|
printf("--->");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
top--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main()
|
|
|
|
|
{
|
|
|
|
|
init();
|
|
|
|
|
int x;
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
printf("**********************************************************************\n");
|
|
|
|
|
printf("* 欢迎使用北京地铁路线规划系统 *\n");
|
|
|
|
|
printf("**********************************************************************\n");
|
|
|
|
|
printf("\n 0、退出程序 ");
|
|
|
|
|
printf("\n 1、输出所有站点及其介绍");
|
|
|
|
|
printf("\n 2、查询某一地铁站点及其介绍");
|
|
|
|
|
printf("\n 3、查询某一站点到其他所有站点的最短路径");
|
|
|
|
|
printf("\n 4、查询某两个站点之间的最短路径 ");
|
|
|
|
|
printf("\n*******************************************************************");
|
|
|
|
|
printf("地点编号对应:\n");
|
|
|
|
|
printf(" 1.苹果园 2.古城 3.八角游乐园 4.公主坟 5.复兴门 6.天安门西 7.建国门 8.永安门 9.鼓楼大街 10.雍和宫\n");
|
|
|
|
|
printf("11.朝阳门 12.北京站 13.崇文门 14.和平门 15.宣武门 16.长椿街 17.西直门 18.圆明园 19.北京大学东门 20.中关村 21.海淀黄庄 22.人民大学 23.国家图书馆 24.动物园 25.北京南站 26.西红门 27.生物医药基地 28天坛东门 29.天通苑 30.天通苑北\n ");
|
|
|
|
|
printf("\n请输入选项:");
|
|
|
|
|
scanf("%d", &x);
|
|
|
|
|
if (x == 0)
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
switch (x)
|
|
|
|
|
{
|
|
|
|
|
case 1:queryAllSite(); break;
|
|
|
|
|
case 2:querySite(); break;
|
|
|
|
|
case 3:dijkstraAllSite(); printAllSite(); break;
|
|
|
|
|
case 4:dijkstraAllSite(); printTwoSite(); break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
system("cls");
|
|
|
|
|
}
|
|
|
|
|
}
|