-
大小: 91KB文件類(lèi)型: .zip金幣: 2下載: 0 次發(fā)布日期: 2021-06-08
- 語(yǔ)言: 其他
- 標(biāo)簽:
資源簡(jiǎn)介
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)大作業(yè),交通咨詢(xún)模擬。1.出于不同目的的旅客對(duì)交通工具有不同的要求。例如,因公出差的旅客希望在旅途中的時(shí)間盡可能短,出門(mén)旅游的旅客則期望旅費(fèi)盡可能省,而老年旅客則要求中轉(zhuǎn)次數(shù)最少。編制一個(gè)全國(guó)城市間的交通咨詢(xún)程序,為旅客提供兩種或三種最優(yōu)決策的交通咨詢(xún)。
2.基本要求
(1)提供對(duì)城市信息進(jìn)行編輯(如:添加或刪除)的功能。
(2)城市之間有兩種交通工具:火車(chē)和飛機(jī)。提供對(duì)列車(chē)時(shí)刻表和飛機(jī)航班進(jìn)行編輯(增設(shè)或刪除)的功能。
(3)提供兩種最優(yōu)決策:最快到達(dá)或最省錢(qián)到達(dá)。全程只考慮一種交通工具。
(4)旅途中耗費(fèi)的總時(shí)間應(yīng)該包括中轉(zhuǎn)站的等候時(shí)間。
(5)咨詢(xún)以用戶(hù)和計(jì)算機(jī)的對(duì)話(huà)方式進(jìn)行。由用戶(hù)輸入起始站、終點(diǎn)站、最優(yōu)決策原則和交通工具,輸出信息:最快需要多長(zhǎng)時(shí)間才能到達(dá)或者最少需要多少旅費(fèi)才能到達(dá),并詳細(xì)說(shuō)明依次于何時(shí)乘坐哪一躺列車(chē)或哪一次班機(jī)到何地。

代碼片段和文件信息
#include
#include
using?namespace?std;
#define?Maxn?500
class?graph{
public:
????mapid;
????string?place[Maxn];
????int?tot=0;
????struct?point{
????????int?numdis;
????????int?nowtime;
????????bool?operator<(const?point?&b)const{
????????return?this->dis ????????bool?operator>(const?point?&b)const{
????????return?this->dis>b.dis;}
????};
????struct?line{
????????string?BeginEnd;
????????string?number;
????????int?sted;
????????int?begintimeendtime;
????????int?disprice;
????????int?change(string?s)
????????{
????????????int?res=((s[0]-‘0‘)*10+(s[1]-‘0‘))*60;
????????????res+=((s[3]-‘0‘)*10+(s[4]-‘0‘));
????????????return?res;
????????}
????????line()
????????{
????????????Begin=““;End=““;number=““;
????????????st=ed=begintime=endtime=price=0;
????????}
????????line(string?numstring?astring?bstring?cstring?dint?sint?tint?p)
????????{
????????????number=num;Begin=a;End=b;
????????????begintime=change(c);endtime=change(d);
????????????st=s;ed=t;
????????????price=p;
????????}
????????void?showtime(int?t)
????????{
????????????printf(“%02d:%02d“t/60t%60);
????????}
????????void?print()
????????{
????????????cout< ????????????showtime(begintime);cout<<“?“;showtime(endtime);cout<<“?“;
????????????cout< ????????}
????};//邊的各種信息,構(gòu)造函數(shù)
????vectorair[Maxn];
????vectortrain[Maxn];
????graph()
????{
????????tot=0;
????????id.clear();
????????for(int?i=0;i ????????for(int?i=0;i ????}//初始化
????int?passtime(int?xint?ybool?f)
????{
????????if(f)return?0;
????????x=x%1440;
????????y=y%1440;
????????return?(y-x+1440)%1440;
????}
????int?length(line?kint?typepoint?intempint?stint?dis)
????{
????????if(type==1)//求時(shí)間最短
????????{
????????????return?passtime(k.begintimek.endtime0)+passtime(disk.begintimest==intemp.num);
????????}
????????if(type==2)//求花費(fèi)最短
????????{
????????????return?k.price;
????????}
????????if(type==3)//求中轉(zhuǎn)最短
????????{
????????????return?1;
????????}
????}
????void?printpath(int?stint?vline?path[])
????{
????????if(v==st)return?;
????????printpath(stpath[v].stpath);
????????path[v].print();
????}//打印路徑
????void?showshow(int?Time)
????{
????????int?h=Time/60m=Time%60;
????????printf(“%d小時(shí)%d分“hm);
????}//修改時(shí)間格式
????void?shortpath(int?stint?edvector?edge[]int?type)
????{
????????bool?mark[Maxn];
????????int?dis[Maxn];
????????line?path[Maxn];
????????const?int?inf=2000000;
????????int?iv;
????????point?intemp{st00}newtemp;
????????for(i=1;i<=tot;i++)
????????{
????????????mark[i]=false;
????????????dis[i]=inf;
????????}
????????dis[st]=0;
????????priority_queuegreater?>Q;
????????Q.push(intemp);
????????mark[st]=true;
????????while(!Q.empty())
????????{
????????????intemp=Q.top();
????????????Q.pop();
??????????
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件???????11791??2016-12-30?01:29??main.cpp
?????文件???????13235??2016-12-22?19:35??shuju.txt
?????文件???????85618??2017-11-10?12:10??全國(guó)交通咨詢(xún)模擬.docx
評(píng)論
共有 條評(píng)論