#include <iostream>
#include <bits/stdc++.h>
#include <string.h>
#include <set>
#include <list>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <cstdlib>
#include <functional>
#define INF 0x3f3f3f3f
#define eps (1e-8)
using namespace std;
struct Edge
{
int time;//两地之间的所需时间
int connectivity;//图的连通性
int price_soft_sleeper,price_hard_sleeper,price_hard_seat;//两地之间软卧、硬卧、硬座的票价
int distance;//两地之间的距离
} Map[101][101]; //邻接矩阵储存两地之间的信息
int specialty[101];//各地点想要的特产种类的数量
map<string,int>vis1;//标记各城市与数字的关系
map<int,string>vis2;
map<int,string>vis3;//票的种类与数字之间的关系
void set_specialty()//设置各地想要购买的特产
{
specialty[1]=2;
specialty[2]=4;
specialty[3]=3;
specialty[4]=1;
specialty[5]=2;
specialty[6]=1;
specialty[7]=3;
specialty[8]=1;
specialty[9]=3;
specialty[10]=4;
specialty[11]=5;
specialty[12]=1;
specialty[13]=2;
specialty[14]=1;
specialty[15]=4;
specialty[16]=3;
specialty[17]=2;
specialty[18]=1;
specialty[19]=2;
specialty[20]=3;
specialty[21]=2;
specialty[22]=1;
specialty[23]=1;
specialty[24]=2;
specialty[25]=1;
}
void Charge()
{
vis1["乌鲁木齐"]=1;
vis2[1]="乌鲁木齐";
vis1["西宁"]=2;
vis2[2]="西宁";
vis1["兰州"]=3;
vis2[3]="兰州";
vis1["呼和浩特"]=4;
vis2[4]="呼和浩特";
vis1["西安"]=5;
vis2[5]="西安";
vis1["郑州"]=6;
vis2[6]="郑州";
vis1["北京"]=7;
vis2[7]="北京";
vis1["天津"]=8;
vis2[8]="天津";
vis1["徐州"]=9;
vis2[9]="徐州";
vis1["沈阳"]=10;
vis2[10]="沈阳";
vis1["长春"]=11;
vis2[11]="长春";
vis1["哈尔滨"]=12;
vis2[12]="哈尔滨";
vis1["大连"]=13;
vis2[13]="大连";
vis1["成都"]=14;
vis2[14]="成都";
vis1["武汉"]=15;
vis2[15]="武汉";
vis1["上海"]=16;
vis2[16]="上海";
vis1["昆明"]=17;
vis2[17]="昆明";
vis1["贵阳"]=18;
vis2[18]="贵阳";
vis1["株州"]=19;
vis2[19]="株州";
vis1["南昌"]=20;
vis2[20]="南昌";
vis1["福州"]=21;
vis2[21]="福州";
vis1["柳州"]=22;
vis2[22]="柳州";
vis1["南宁"]=23;
vis2[23]="南宁";
vis1["广州"]=24;
vis2[24]="广州";
vis1["深圳"]=25;
vis2[25]="深圳";
vis3[1]="软卧";
vis3[2]="硬卧";
vis3[3]="硬座";
}
void connectivity_time()
{
for(int i=1; i<=25; i++)
{
for(int j=1; j<=25; j++)
{
Map[i][j].time=Map[j][i].time=INF;
}
}
Map[1][3].time=Map[3][1].time=657;
Map[2][3].time=Map[3][2].time=140;
Map[3][4].time=Map[4][3].time=976;
Map[3][5].time=Map[5][3].time=519;
Map[4][7].time=Map[7][4].time=647;
Map[5][6].time=Map[6][5].time=385;
Map[6][7].time=Map[7][6].time=164;
Map[6][9].time=Map[9][6].time=246;
Map[7][8].time=Map[8][7].time=30;
Map[8][10].time=Map[10][8].time=561;
Map[10][11].time=Map[11][10].time=186;
Map[11][12].time=Map[12][11].time=175;
Map[10][13].time=Map[13][10].time=321;
Map[8][9].time=Map[9][8].time=542;
Map[5][14].time=Map[14][5].time=932;
Map[6][15].time=Map[15][6].time=204;
Map[14][17].time=Map[17][14].time=405;
Map[14][18].time=Map[18][14].time=207;
Map[17][18].time=Map[18][17].time=467;
Map[18][19].time=Map[19][18].time=819;
Map[18][22].time=Map[22][18].time=243;
Map[15][19].time=Map[19][15].time=110;
Map[19][20].time=Map[20][19].time=247;
Map[16][20].time=Map[20][16].time=242;
Map[9][16].time=Map[16][9].time=525;
Map[20][21].time=Map[21][20].time=217;
Map[19][22].time=Map[22][19].time=534;
Map[19][24].time=Map[24][19].time=154;
Map[22][23].time=Map[23][22].time=225;
Map[24][25].time=Map[25][24].time=133;
}
void connectivity_price()
{
for(int i=1; i<=25; i++)
{
for(int j=1; j<=25; j++)
{
Map[i][j].price_hard_seat=INF;
Map[i][j].price_hard_sleeper=INF;
Map[i][j].price_soft_sleeper=INF;
}
}
Map[1][3].price_soft_sleeper=Map[3][1].price_soft_sleeper=882;
Map[2][3].price_soft_sleeper=Map[3][2].price_soft_sleeper=INF;
Map[3][4].price_soft_sleeper=Map[4][3].price_soft_sleeper=398.5;
Map[3][5].price_soft_sleeper=Map[5][3].price_soft_sleeper=251;
Map[4][7].price_soft_sleeper=Map[7][4].price_soft_sleeper=233;
Map[5][6].price_soft_sleeper=Map[6][5].price_soft_sleeper=197;
Map[6][7].price_soft_sleeper=Map[7][6].price_soft_sleeper=INF;
Map[6][9].price_soft_sleeper=Map[9][6].price_soft_sleeper=149.5;
Map[7][8].price_soft_sleeper=Map[8][7].price_soft_sleeper=174;
Map[8][10].price_soft_sleeper=Map[10][8].price_soft_sleeper=263;
Map[10][11].price_soft_sleeper=Map[11][10].price_soft_sleeper=140.5;
Map[11][12].price_soft_sleeper=Map[12][11].price_soft_sleeper=129.5;
Map[10][13].price_soft_sleeper=Map[13][10].price_soft_sleeper=155.5;
Map[8][9].price_soft_sleeper=Map[9][8].price_soft_sleeper=251;
Map[5][14].price_soft_sleeper=Map[14][5].price_soft_sleeper=301;
Map[6][15].price_soft_sleeper=Map[15][6].price_soft_sleeper=197;
Map[14][17].price_soft_sleeper=Map[17][14].price_soft_sleeper=INF;
Map[14][18].price_soft_sleeper=Map[18][14].price_soft_sleeper=INF;
Map[17][18].price_soft_sleeper=Map[18][17].price_soft_sleeper=233;
Map[18][19].price_soft_sleeper=Map[19][18].price_soft_sleeper=312;
Map[18][22].price_soft_sleeper=Map[22][18].price_soft_sleeper=INF;
Map[15][19].price_soft_sleeper=Map[19][15].price_soft_sleeper=INF;
Map[19][20].price_soft_sleeper=Map[20][19].price_soft_sleeper=152.5;
Map[16][20].price_soft_sleeper=Map[20][16].price_soft_sleeper=INF;
Map[9][16].price_soft_sleeper=Map[16][9].price_soft_sleeper=243;
Map[20][21].price_soft_sleeper=Map[21][20].price_soft_sleeper=INF;
Map[19][22].price_soft_sleeper=Map[22][19].price_soft_sleeper=223;
Map[19][24].price_soft_sleeper=Map[24][19].price_soft_sleeper=INF;
Map[22][23].price_soft_sleeper=Map[23][22].price_soft_sleeper=129.5;
Map[24][25].price_soft_sleeper=Map[25][24].price_soft_sleeper=INF;
///
Map[1][3].price_hard_sleeper=Map[3][1].price_hard_sleeper=551;
Map[2][3].price_hard_sleeper=Map[3][2].price_hard_sleeper=INF;
Map[3][4].price_hard_sleeper=Map[4][3].price_hard_sleeper=254.5;
Map[3][5].price_hard_sleeper=Map[5][3].price_hard_sleeper=163;
Map[4][7].price_hard_sleeper=Map[7][4].price_hard_sleeper=152;
Map[5][6].price_hard_sleeper=Map[6][5].price_hard_sleeper=129;
Map[6][7].price_hard_sleeper=Map[7][6].price_hard_sleeper=INF;
Map[6][9].price_hard_sleeper=Map[9][6].price_hard_sleeper=97.5;
Map[7][8].price_hard_sleeper=Map[8][7].price_hard_sleeper=88;
Map[8][10].price_hard_sleeper=Map[10][8].price_hard_sleeper=171;
Map[10][11].price_hard_sleeper=Map[11][10].price_hard_sleeper=92.5;
Map[11][12].price_hard_sleeper=Map[12][11].price_hard_sleeper=86.5;
Map[10][13].price_hard_sleeper=Map[13][10].price_hard_sleeper=100.5;
Map[8][9].price_hard_sleeper=Map[9][8].price_hard_sleeper=163;
Map[5][14].price_hard_sleeper=Map[14][5].price_hard_sleeper=194;
Map[6][15].price_hard_sleeper=Map[15][6].price_hard_sleeper=129;
Map[14][17].price_hard_sleeper=Map[17][14].price_hard_sleeper=INF;
Map[14][18].price_hard_sleeper=Map[18][14].price_hard_sleeper=INF;
Map[17][18].price_hard_sleeper=Map[18][17].price_hard_sleeper=152;
Map[18][19].price_hard_sleeper=Map[19][18].price_hard_sleeper=200;
Map[18][22].price_hard_sleeper=Map[22][18].price_hard_sleeper=INF;
Map[15][19].price_hard_sleeper=Map[19][15].price_hard_sleeper=INF;
Map[19][20].price_hard_sleeper=Map[20][19].price_hard_sleeper=99.5;
Map[16][20].price_hard_sleeper=Map[20][16].price_hard_sleeper=INF;
Map[9][16].price_hard_sleeper=Map[16][9].price_hard_sleeper=158;
Map[20][21].price_hard_sleeper=Map[21][20].price_hard_sleeper=INF;
Map[19][22].price_hard_sleeper=Map[22][19].price_hard_sleeper=152;
Map[19][24].price_hard_sleeper=Map[24][19].price_hard_sleeper=INF;
Map[22][23].price_hard_sleeper=Map[23][22].price_hard_sleeper=86.5;
Map[24][25].price_hard_sleeper=Map[25][24].price_hard_sleeper=145.5;
///
Map[1][3].price_hard_seat=Map[3][1].price_hard_seat=450;
Map[2][3].price_hard_seat=Map[3][2].price_hard_seat=40;
Map[3][4].price_hard_seat=Map[4][3].price_hard_seat=148.5;
Map[3][5].price_hard_seat=Map[5][3].price_hard_seat=93;
Map[4][7].price_hard_seat=Map[7][4].price_hard_seat=86;
Map[5][6].price_hard_seat=Map[6][5].price_hard_seat=72;
Map[6][7].price_hard_seat=Map[7][6].price_hard_seat=309;
Map[6][9].price_hard_seat=Map[9][6].price_hard_seat=51.5;
Map[7][8].price_hard_seat=Map[8][7].price_hard_seat=54.5;
Map[8][10].price_hard_seat=Map[10][8].price_hard_seat=98;
Map[10][11].price_hard_seat=Map[11][10].price_hard_seat=46.5;
Map[11][12].price_hard_seat=Map[12][11].price_hard_seat=40.5;
Map[10][13].price_hard_seat=Map[13][10].price_hard_seat=54.5;
Map[8][9].price_hard_seat=Map[9][8].price_hard_seat=93;
Map[5][14].price_hard_seat=Map[14][5].price_hard_seat=112;
Map[6][15].price_hard_seat=Map[15][6].price_hard_seat=72;
Map[14][17].price_hard_seat=Map[17][14].price_hard_seat=500;
Map[14][18].price_hard_seat=Map[18][14].price_hard_seat=268;
Map[17][18].price_hard_seat=Map[18][17].price_hard_seat=86;
Map[18][19].price_hard_seat=Map[19][18].price_hard_seat=115;
Map[18][22].price_hard_seat=Map[22][18].price_hard_seat=211.5;
Map[15][19].price_hard_seat=Map[19][15].price_hard_seat=304;
Map[19][20].price_hard_seat=Map[20][19].price_hard_seat=53.5;
Map[16][20].price_hard_seat=Map[20][16].price_hard_seat=336.5;
Map[9][16].price_hard_seat=Map[16][9].price_hard_seat=91;
Map[20][21].price_hard_seat=Map[21][20].price_hard_seat=169;
Map[19][22].price_hard_seat=Map[22][19].price_hard_seat=86;
Map[19][24].price_hard_seat=Map[24][19].price_hard_seat=294;
Map[22][23].price_hard_seat=Map[23][22].price_hard_seat=40.5;
Map[24][25].price_hard_seat=Map[25][24].price_hard_seat=65.5;
}
void connectivity_distance()
{
for(int i=1; i<=25; i++)
{
for(int j=1; j<=25; j++)
{
Map[i][j].distance=INF;
Map[i][j].connectivity=0;
}
}
///连通性
Map[1][3].connectivity=Map[3][1].connectivity=1;
Map[2][3].connectivity=Map[3][2].connectivity=1;
Map[3][4].connectivity=Map[4][3].connectivity=1;
Map[3][5].connectivity=Map[5][3].connectivity=1;
Map[4][7].connectivity=Map[7][4].connectivity=1;
Map[5][6].connectivity=Map[6][5].connectivity=1;
Map[6][7].connectivity=Map[7][6].connectivity=1;
Map[6][9].connectivity=Map[9][6].connectivity=1;
Map[7][8].connectivity=Map[8][7].connectivity=1;
Map[8][10].connectivity=Map[10][8].connectivity=1;
Map[10][11].connectivity=Map[11][10].connectivity=1;
Map[11][12].connectivity=Map[12][11].connectivity=1;
Map[10][13].connectivity=Map[13][10].connectivity=1;
Map[8][9].connectivity=Map[9][8].connectivity=1;
Map[5][14].connectivity=Map[14][5].connectivity=1;
Map[6][15].connectivity=Map[15][6].connectivity=1;
Map[14][17].connectivity=Map[17][14].connectivity=1;
Map[14][18].connectivity=Map[18][14].connectivity=1;
Map[17][18].connectivity=Map[18][17].connectivity=1;
Map[18][19].connectivity=Map[19][18].connectivity=1;
Map[18][22].connectivity=Map[22][18].connectivity=1;
Map[15][19].connectivity=Map[19][15].connectivity=1;
Map[19][20].connectivity=Map[20][19].connectivity=1;
Map[16][20].connectivity=Map[20][16].connectivity=1;
Map[9][16].connectivity=Map[16][9].connectivity=1;
Map[20][21].connectivity=Map[21][20].connectivity=1;
Map[19][22].connectivity=Map[22][19].connectivity=1;
Map[19][24].connectivity=Map[24][19].connectivity=1;
Map[22][23].connectivity=Map[23][22].connectivity=1;
Map[24][25].connectivity=Map[25][24].connectivity=1;
///
Map[1][3].distance=Map[3][1].distance=1892;
Map[2][3].distance=Map[3][2].distance=216;
Map[3][4].distance=Map[4][3].distance=1145;
Map[3][5].distance=Map[5][3].distance=676;
Map[4][7].distance=Map[7][4].distance=668;
Map[5][6].distance=Map[6][5].distance=511;
Map[6][7].distance=Map[7][6].distance=695;
Map[6][9].distance=Map[9][6].distance=349;
Map[7][8].distance=Map[8][7].distance=137;
Map[8][10].distance=Map[10][8].distance=704;
Map[10][11].distance=Map[11][10].distance=305;
Map[11][12].distance=Map[12][11].distance=242;
Map[10][13].distance=Map[13][10].distance=397;
Map[8][9].distance=Map[9][8].distance=674;
Map[5][14].distance=Map[14][5].distance=842;
Map[6][15].distance=Map[15][6].distance=534;
Map[14][17].distance=Map[17][14].distance=1100;
Map[14][18].distance=Map[18][14].distance=967;
Map[17][18].distance=Map[18][17].distance=639;
Map[18][19].distance=Map[19][18].distance=902;
Map[18][22].distance=Map[22][18].distance=607;
Map[15][19].distance=Map[19][15].distance=409;
Map[19][20].distance=Map[20][19].distance=367;
Map[16][20].distance=Map[20][16].distance=825;
Map[9][16].distance=Map[16][9].distance=651;
Map[20][21].distance=Map[21][20].distance=622;
Map[19][22].distance=Map[22][19].distance=672;
Map[19][24].distance=Map[24][19].distance=675;
Map[22][23].distance=Map[23][22].distance=255;
Map[24][25].distance=Map[25][24].distance=140;
}
int pre[101];//储存该地点之前经过的地点
int cnt;
int minn_path[101];
int sum_specialty[101];
int book[101];
int pace[101];//记录最短路径的个数
void Minn_distance(int Start)
{
pace[Start]=book[Start]=1;//最短路径也要相应初始化
for(int i=1; i<=25; i++)
{
minn_path[i]=Map[Start][i].distance;
}
for(int i=0; i<24; i++) //仅遍历n-1次即可;
{
int minn=INF,f=-1;//f赋初值-1
for(int j=1; j<=25; j++) //寻找当前未被标记的且里出发地最近的点
{
if(!book[j]&&minn_path[j]<minn)
{
minn=minn_path[j];
f=j;
}
}
if(f==-1) break;
book[f]=1;//该点标记
for(int j=1; j<=25; j++) //以该点位中转站,对未标记的的点松弛
{
if(!book[j]&&minn_path[j]>minn_path[f]+Map[f][j].distance)
{
minn_path[j]=minn_path[f]+Map[f][j].distance;//路径长度更新
pre[j]=f;//记录上一节点位置
pace[j]=pace[f];//当前最短路径的个数
sum_specialty[j]=sum_specialty[f]+specialty[j];//特产种数
}
else if(!book[j]&&minn_path[j]==minn_path[f]+Map[f][j].distance)
{
pace[j]+=pace[f];//当前也为最短路径,数目加一
if(sum_specialty[j]<sum_specialty[f]+specialty[j]) //实时更新可召集救援队总数目
{
pre[j]=f;
sum_specialty[j]=sum_specialty[f]+specialty[j];
}
}
}
}
}
int book_transfer[101];
void bfs_Minn_transfer(int Start)
{
int que[101];
int head=0,tail=0;
que[tail++]=Start;
book_transfer[Start]=1;
while(head<tail)
{
int top=que[head++];
for(int i=1; i<=25; i++)
{
if(!book_transfer[i]&&Map[top][i].connectivity==1)
{
que[tail++]=i;
book_transfer[i]=1;
pre[i]=top;
}
}
}
return;
}
int book_time[101];
int minn_time[101];
void Minn_time(int Start)
{
pace[Start]=book[Start]=1;//最短路径也要相应初始化
for(int i=1; i<=25; i++)
{
minn_time[i]=Map[Start][i].time;
}
for(int i=0; i<24; i++) //仅遍历n-1次即可;
{
int minn=INF,f=-1;//f赋初值-1
for(int j=1; j<=25; j++) //寻找当前未被标记的且里出发地最近的点
{
if(!book_time[j]&&minn_time[j]<minn)
{
minn=minn_time[j];
f=j;
}
}
if(f==-1) break;
book_time[f]=1;//该点标记
for(int j=1; j<=25; j++) //以该点位中转站,对未标记的的点松弛
{
if(!book_time[j]&&minn_time[j]>minn_time[f]+Map[f][j].time)
{
minn_time[j]=minn_time[f]+Map[f][j].time;//路径长度更新
pre[j]=f;//记录上一节点位置
pace[j]=pace[f];//当前最短路径的个数
sum_specialty[j]=sum_specialty[f]+specialty[j];//特产种数
}
else if(!book[j]&&minn_time[j]==minn_time[f]+Map[f][j].time)
{
pace[j]+=pace[f];//当前也为最短路径,数目加一
if(sum_specialty[j]<sum_specialty[f]+specialty[j]) //实时更新可召集救援队总数目
{
pre[j]=f;
sum_specialty[j]=sum_specialty[f]+specialty[j];
}
}
}
}
}
int book_money[101];
int minn_money[101];
void Minn_money(int Start)
{
pace[Start]=book[Start]=1;//最短路径也要相应初始化
for(int i=1; i<=25; i++)
{
minn_money[i]=Map[Start][i].price_hard_seat;
}
for(int i=0; i<24; i++) //仅遍历n-1次即可;
{
int minn=INF,f=-1;//f赋初值-1
for(int j=1; j<=25; j++) //寻找当前未被标记的且里出发地最近的点
{
if(!book_money[j]&&minn_money[j]<minn)
{
minn=minn_money[j];
f=j;
}
}
if(f==-1) break;
book_money[f]=1;//该点标记
for(int j=1; j<=25; j++) //以该点位中转站,对未标记的的点松弛
{
if(!book_money[j]&&minn_money[j]>minn_money[f]+Map[f][j].price_hard_seat)
{
minn_money[j]=minn_money[f]+Map[f][j].price_hard_seat;//路径长度更新
pre[j]=f;//记录上一节点位置
pace[j]=pace[f];//当前最短路径的个数
sum_specialty[j]=sum_specialty[f]+specialty[j];//特产种数
}
else if(!book_money[j]&&minn_money[j]==minn_money[f]+Map[f][j].price_hard_seat)
{
pace[j]+=pace[f];//当前也为最短路径,数目加一
if(sum_specialty[j]<sum_specialty[f]+specialty[j]) //实时更新可召集救援队总数目
{
pre[j]=f;
sum_specialty[j]=sum_specialty[f]+specialty[j];
}
}
}
}
}
int main()
{
cout<<"============================欢迎使用slyarh选票系统============================"<<endl<<endl;
int i=0;
Charge();
connectivity_distance();
connectivity_price();
connectivity_time();
set_specialty();
while(i!=5)
{
cout<<"目标1:距离最短"<<" "<<"目标2:换乘次数最少"<<" "<<"目标3:预计耗费时间最短"<<" "<<"目标4:票价总和最小"<<" "<<"目标5:退出系统"<<endl<<endl;
cout<<"请选择您的目标:";
cin>>i;
switch(i)
{
case 1:
{
string str1,str2;
cout<<"请输入您的起始地点:";
cin>>str1;
cout<<endl;
cout<<"请输入您的目标地点:";
cin>>str2;
cout<<endl;
int Start=vis1[str1],End=vis1[str2];
memset(pre,0,sizeof(pre));
memset(book,0,sizeof(book));
for(int i=1; i<=25; i++)
{
sum_specialty[i]=specialty[i];
pace[i]=1;
}
Minn_distance(Start);
cout<<"从"<<str1<<"到"<<str2<<"的距离最短路径有"<<pace[End]<<"条"<<endl;
cout<<"从中任选一条路径,输出其从起始地点到目标地点的路线:"<<endl;
int road[101];
int cur=End,cnt=0;
int ticket[101];
road[cnt++]=End;
while(pre[cur]!=0)
{
road[cnt++]=pre[cur];
cur=pre[cur];
}
road[cnt++]=Start;
//cout<<vis2[road[j]]<<"("<<vis3[ticket[j]]<<")";
int sum_money=0;
for(int j=cnt-1; j>=0; j--)
{
if(j!=0)
{
cout<<"从"<<vis2[road[j]]<<"到"<<vis2[road[j-1]]<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
int kind;
while(cin>>kind)
{
int flag=0;
switch(kind)
{
case 1:
{
flag=1;
ticket[j]=1;
if(Map[road[j]][road[j-1]].price_soft_sleeper==INF)//软卧无票
{
flag=0;
cout<<"您选择的软卧暂时没有票了~,请重新选择一个吧"<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
}
else
{
sum_money=sum_money+Map[road[j]][road[j-1]].price_soft_sleeper;
}
}
break;
case 2:
{
flag=1;
ticket[j]=2;
if(Map[road[j]][road[j-1]].price_hard_sleeper==INF)//软卧无票
{
flag=0;
cout<<"您选择的硬卧暂时没有票了~,请重新选择一个吧"<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
}
else
{
sum_money=sum_money+Map[road[j]][road[j-1]].price_hard_sleeper;
}
}
break;
case 3:
{
flag=1;
ticket[j]=3;
if(Map[road[j]][road[j-1]].price_hard_seat==INF)//软卧无票
{
flag=0;
cout<<"您选择的硬卧暂时没有票了~,请重新选择一个吧"<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
}
else
{
sum_money=sum_money+Map[road[j]][road[j-1]].price_hard_seat;
}
}
break;
default:
cout<<"您的输入有误,请检查后重新输入"<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
}
if(flag)
{
break;
}
}
}
}
for(int j=cnt-1; j>=0; j--)
{
if(j>0)
{
cout<<vis2[road[j]]<<"("<<vis3[ticket[j]]<<")"<<"->";
}
else
{
cout<<vis2[road[j]]<<endl;
}
}
cout<<endl;
cout<<"从"<<str1<<"到"<<str2<<"总共花费"<<sum_money<<endl<<endl;
cout<<"从"<<str1<<"到"<<str2<<"能够带"<<specialty[Start]+sum_specialty[End]<<"种特产"<<endl;
}
break;
case 2:
{
string str1,str2;
cout<<"请输入您的起始地点:";
cin>>str1;
cout<<endl;
cout<<"请输入您的目标地点:";
cin>>str2;
cout<<endl;
int Start=vis1[str1],End=vis1[str2];
cnt=0;
memset(book_transfer,0,sizeof(book));
bfs_Minn_transfer(Start);
cout<<"换乘次数最少的路线为:";
int Sum_specialty=0;
int road[101],ticket[101],sum_money=0;
int cur=End,cnt=0;
road[cnt++]=End;
Sum_specialty+=specialty[End];
while(pre[cur]!=0)
{
road[cnt++]=pre[cur];
Sum_specialty+=specialty[pre[cur]];
cur=pre[cur];
}
for(int j=cnt-1; j>=0; j--)
{
if(j!=0)
{
cout<<"从"<<vis2[road[j]]<<"到"<<vis2[road[j-1]]<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
int kind;
while(cin>>kind)
{
int flag=0;
switch(kind)
{
case 1:
{
flag=1;
ticket[j]=1;
if(Map[road[j]][road[j-1]].price_soft_sleeper==INF)//软卧无票
{
flag=0;
cout<<"您选择的软卧暂时没有票了~,请重新选择一个吧"<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
}
else
{
sum_money=sum_money+Map[road[j]][road[j-1]].price_soft_sleeper;
}
}
break;
case 2:
{
flag=1;
ticket[j]=2;
if(Map[road[j]][road[j-1]].price_hard_sleeper==INF)//软卧无票
{
flag=0;
cout<<"您选择的硬卧暂时没有票了~,请重新选择一个吧"<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
}
else
{
sum_money=sum_money+Map[road[j]][road[j-1]].price_hard_sleeper;
}
}
break;
case 3:
{
flag=1;
ticket[j]=3;
if(Map[road[j]][road[j-1]].price_hard_seat==INF)//软卧无票
{
flag=0;
cout<<"您选择的硬卧暂时没有票了~,请重新选择一个吧"<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
}
else
{
sum_money=sum_money+Map[road[j]][road[j-1]].price_hard_seat;
}
}
break;
default:
cout<<"您的输入有误,请检查后重新输入"<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
}
if(flag)
{
break;
}
}
}
}
for(int j=cnt-1; j>=0; j--)
{
if(j>0)
{
cout<<vis2[road[j]]<<"("<<vis3[ticket[j]]<<")"<<"->";
}
else
{
cout<<vis2[road[j]]<<endl;
}
}
cout<<endl;
cout<<"从"<<str1<<"到"<<str2<<"总共花费"<<sum_money<<endl<<endl;
cout<<"从"<<str1<<"到"<<str2<<"能够带"<<Sum_specialty<<"种特产"<<endl;
}
break;
case 3:
{
string str1,str2;
cout<<"请输入您的起始地点:";
cin>>str1;
cout<<endl;
cout<<"请输入您的目标地点:";
cin>>str2;
cout<<endl;
int Start=vis1[str1],End=vis1[str2];
memset(book_time,0,sizeof(book_time));
memset(pre,0,sizeof(pre));
for(int i=1; i<=25; i++)
{
sum_specialty[i]=specialty[i];
pace[i]=1;
}
Minn_distance(Start);
cout<<"从"<<str1<<"到"<<str2<<"花费时间最短的路径"<<pace[End]<<"条"<<endl;
cout<<"从中任选一条路径,输出其从起始地点到目标地点的路线:"<<endl;
int road[101],ticket[101],sum_money=0;
int cur=End,cnt=0;
road[cnt++]=End;
while(pre[cur]!=0)
{
road[cnt++]=pre[cur];
cur=pre[cur];
}
road[cnt++]=Start;
for(int j=cnt-1; j>=0; j--)
{
if(j!=0)
{
cout<<"从"<<vis2[road[j]]<<"到"<<vis2[road[j-1]]<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
int kind;
while(cin>>kind)
{
int flag=0;
switch(kind)
{
case 1:
{
flag=1;
ticket[j]=1;
if(Map[road[j]][road[j-1]].price_soft_sleeper==INF)//软卧无票
{
flag=0;
cout<<"您选择的软卧暂时没有票了~,请重新选择一个吧"<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
}
else
{
sum_money=sum_money+Map[road[j]][road[j-1]].price_soft_sleeper;
}
}
break;
case 2:
{
flag=1;
ticket[j]=2;
if(Map[road[j]][road[j-1]].price_hard_sleeper==INF)//软卧无票
{
flag=0;
cout<<"您选择的硬卧暂时没有票了~,请重新选择一个吧"<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
}
else
{
sum_money=sum_money+Map[road[j]][road[j-1]].price_hard_sleeper;
}
}
break;
case 3:
{
flag=1;
ticket[j]=3;
if(Map[road[j]][road[j-1]].price_hard_seat==INF)//软卧无票
{
flag=0;
cout<<"您选择的硬卧暂时没有票了~,请重新选择一个吧"<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
}
else
{
sum_money=sum_money+Map[road[j]][road[j-1]].price_hard_seat;
}
}
break;
default:
cout<<"您的输入有误,请检查后重新输入"<<endl;
cout<<"1.软卧"<<" "<<"2.硬卧"<<" "<<"3.硬座"<<endl;
cout<<"请选择票的种类:";
}
if(flag)
{
break;
}
}
}
}
for(int j=cnt-1; j>=0; j--)
{
if(j>0)
{
cout<<vis2[road[j]]<<"("<<vis3[ticket[j]]<<")"<<"->";
}
else
{
cout<<vis2[road[j]]<<endl;
}
}
cout<<endl;
cout<<"从"<<str1<<"到"<<str2<<"总共花费"<<sum_money<<endl<<endl;
cout<<"从"<<str1<<"到"<<str2<<"总共花费"<<minn_time[End]<<"分钟"<<endl<<endl;
cout<<"从"<<str1<<"到"<<str2<<"能够带"<<specialty[Start]+sum_specialty[End]<<"种特产"<<endl;
}
break;
case 4:
{
string str1,str2;
cout<<"请输入您的起始地点:";
cin>>str1;
cout<<endl;
cout<<"请输入您的目标地点:";
cin>>str2;
cout<<endl;
int Start=vis1[str1],End=vis1[str2];
memset(book_money,0,sizeof(book_money));
memset(pre,0,sizeof(pre));
for(int i=1; i<=25; i++)
{
sum_specialty[i]=specialty[i];
pace[i]=1;
}
Minn_money(Start);
cout<<"从"<<str1<<"到"<<str2<<"花费最少有"<<pace[End]<<"条"<<endl;
cout<<"从中任选一条路径,输出其从起始地点到目标地点的路线:"<<endl;
int road[101];
int cur=End,cnt=0;
road[cnt++]=End;
while(pre[cur]!=0)
{
road[cnt++]=pre[cur];
cur=pre[cur];
}
road[cnt++]=Start;
for(int j=cnt-1; j>=0; j--)
{
if(j!=cnt-1)
{
cout<<"->";
}
cout<<vis2[road[j]];
}
cout<<endl;
cout<<"从"<<str1<<"到"<<str2<<"能够带"<<specialty[Start]+sum_specialty[End]<<"种特产"<<endl;
}
break;
case 5:
cout<<"===============================已退出slyarh系统==============================="<<endl<<endl;
break;
default:
cout<<"您的输入有误,请检查后重新输入~"<<endl;
}
}
return 0;
}
回家之旅
最新推荐文章于 2022-08-09 14:58:08 发布