航車演算法
1. 船位推演算法是什麼
確定船位:航跡推演算法和觀測定位法。
航跡推算(track estimation):以起航點或觀測船位為推算起始點,根據船舶最基本的航海儀器(羅經和計程儀)所指示的航向、航程,以及船舶的操縱要素和風流要素等,在不藉助外界導航物標的條件下,推算出具有一定精度的航跡和船位的方法和過程。
觀測定位(positioning by observing):航海人員利用各種航海儀器觀測位置已知的外界物標,並根據觀測結果確定出觀測時船位的方法和過程。
航跡推算起始點(時):駛離港口引航水域或港界,定速航行並獲得准確的觀測船位後立即進行。
終止(時):抵達目的港的引航水域,或接近港界有物標或航標可供目測定位或導航時,方可終止航跡推算。
航跡推算工作不得無故中斷,僅當船舶駛入狹水道、漁區、船舶密集區域需頻繁使用車、舵的情況下,方可中斷航跡推算工作。當恢復正常後應立即恢復航跡推算工作,推算中止點和復始點的時間和位置應在海圖上畫出,並記入航海日誌。
船舶在沿岸水流影響顯著的海區航行,應該每1小時確定一次推算船位;其它海區一般每2~4小時確定一次推算船位。
航跡推算:航跡繪演算法(track plotting)和航跡計演算法(track calculating)。
2. 急:求渡口管理問題的演算法和動畫演示
渡口管理問題
題目:
某汽車輪渡口,過江渡船每次只能載10輛車過江。過江車輛分為客車類和貨車類,上船有如下規定:同類車先到先上船,客車先於貨車上渡船,且每上4輛客車,才允許上一輛貨車;若等待客不足4輛,則以貨車代替,若無貨車等待則允許客車都上船。
根據描述設計一個演算法模擬渡口管理。
提示:
初始化,上渡船汽車數量x,上船客車數y,上船貨車數z;討論在上渡船汽車數量小於10的情形:
1 若x<4,客車隊列又非空,將客車隊列的隊頭汽車出隊上渡船。X 和Y增1,否則轉2
2、若Y》=4,或客車隊列為空隊且貨車隊列非空,將貨車隊列的隊頭汽車出隊上渡船。Y=0,X和Z增1,
否則轉3
3、若貨車隊列為空隊且客車隊非空,將客車隊列的隊頭汽車出隊上渡船。X和Y增1,Z=0;否則轉4
4、提示相應錯誤信息並退出程序運行。
#include<queue>
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
queue<string> q_keche, q_huoche;
string input_data, huoche="huoche", keche="keche";
int Max=10;
int k=0,h=0;
while (cin>>input_data)
{
stringstream out;
if (input_data == huoche)
{
cout <<"huoche size before adding: "<<q_huoche.size()<<" ";
out<<(++h);
q_huoche.push(huoche+out.str());
cout <<q_huoche.back()<<" in the queue, total huoche: "<<q_huoche.size()<<" "<<endl;
}
else if (input_data == keche)
{
cout <<"Keche size before adding: "<<q_keche.size()<<" ";
out<<(++k);
q_keche.push(keche+out.str());
cout <<q_keche.back()<<" in the queue, total keche: "<<q_keche.size()<<" "<<endl;
}
else break;
}
cout <<"2 queues info:\nTotal Keche Size: "<<q_keche.size()<<endl
<<"Toatl Huoche Size: "<<q_huoche.size()<<endl;
if ( q_keche.empty() && (!q_huoche.empty()))
while (!q_huoche.empty())
{
cout<<"huoche Size: "<<q_huoche.size()
<<"huoche will load on the ship: "<<q_huoche.front()<<endl;
q_huoche.pop();
--Max;
if (Max<=0){
cout<<"The ship is full. Please wait for next ship!!!\n...\n..\n.\n"
<<"The ship is coming, start loading\n";
Max=10;
}
}
else
{
while ((!q_keche.empty() || !q_huoche.empty()))
{
for (int i=0; !q_keche.empty()&& i<4; i++) {
cout<<"Keche Size: "<<q_keche.size()<<" "
<<q_keche.front()<<" will load on the ship: "<<q_keche.front()<<endl;
q_keche.pop();
cout<<"Keche Sizes after loading: "<<q_keche.size()<<endl;
--Max;
}
if (!q_huoche.empty())
{
cout<<"huoche Size: "<<q_huoche.size()<<" "
<<q_huoche.front()<<" huoche will load: "<<q_huoche.front()<<endl;
q_huoche.pop();
cout <<"huoche Sizes after loading: "<<q_huoche.size()<<endl;
--Max;
}
if (Max<=0){
cout<<"The ship is full. Please wait for next ship!!!\n...\n..\n.\n"
<<"The ship is coming, start loading\n";
Max=10;
}
}
}
}