我误解了规则,我必须尽可能乘坐最近的航班......
// lets find all airports which allows flights from home city and so on..
int min;// minimum value
int minc;// minimal coordinate
int mine;//real position of edge in array
int fakehome = 0;// temprorary position for house
int lastmine = -1;//last position, so can compare times
//cout << timeToInt(begintime);
cout << home << " " << begintime<< endl;
fout << home << " " << begintime<< endl;
while(home != aim)// loop while we havent reached aim/target airport
{
min = 1440;// 24(hours) * 60 is unreachable value, so 1440 minuts ok
minc = ports;// max could be count(of airports)
mine = edges_counter;// array position of edge
//lastmine = -1;
for(int i =0;i< edges_counter;i++)
{
//if(edges[i][0] == home) cout << edges[i][0] << " " << edges[i][1] << " " << edges[i][2] << " " << edges[i][3] << " " << endl;
if(min > edges[i][2] && edges[i][0] == home && edges[i][4] == 0)
{
if(lastmine != -1 && (edges[lastmine][2]+edges[lastmine][3]) < edges[i][2])
{
min = edges[i][2];
minc = edges[i][1];
mine = i;
fakehome = edges[i][1];
}
else if(lastmine == -1 && timeToInt(saklaiks) < edges[i][2])
{
min = edges[i][2];
minc = edges[i][1];
mine = i;
fakehome = edges[i][1];
}
}
}
if(mine != edges_counter)
{
//cout << setw(3) << mine << " ";
intToTime(edges[mine][2],time);
cout << home << "->" << fakehome << " " << time;
fout << home << "->" << fakehome << " " << time;
intToTime((edges[mine][2]+edges[mine][3]), time);
cout << "-" << time<< endl;
fout << "-" << time<< endl;
intToTime((edges[mine][2]+edges[mine][3]),begintime);
home = fakehome;
edges[mine][4] = 1;
}
lastmine = mine;
}
但是有一个问题。。
如果
航班无限循环,无法到达目标。如何检查?
If is given
3 (how much airports)
1 3 (have to go from 1 to 3)
00:00 (start time)
1 2 01:00-02:00 (from 1 to 2 there is flight that takes 1 hour)
2 1 03:00-04:00 (from 2 to 1 there's also flight that takes 1 hour)
2 3 12:00-13:00 (...)
但是由于 2->1 飞行比 2->3 在打印第一个元素之前知道循环的任何想法更快,因此永远不会达到 2->3,因为它正在打印
1->2 ...
2->1 ...
1->2 ...
等等..我必须打印:“不可能”。