commit c2f021fbb382eb20bca95195a5f44946cb191dc5 Author: hladu357 Date: Fri May 17 13:42:41 2024 +0200 BFS teleport diff --git a/teleport.cpp b/teleport.cpp new file mode 100644 index 0000000..e3bf366 --- /dev/null +++ b/teleport.cpp @@ -0,0 +1,185 @@ +#ifndef __PROGTEST__ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#endif /* __PROGTEST__ */ + +// https://fit-wiki.cz/%C5%A1kola/p%C5%99edm%C4%9Bty/bi-pa2/pa2_zkou%C5%A1ka_2023-05-25 + +class CTeleport { +public: + CTeleport() {} + ~CTeleport() {} + + enum City : int {}; + enum Time : int {}; + + struct Port { + public: + Port( City to, Time fromTime, Time toTime ) + : to(to), fromTime(fromTime), toTime(toTime) {} + + City to; + Time fromTime; + Time toTime; + + bool operator<( const Port& oth ) const { + return std::tie(fromTime, toTime, to) < std::tie(oth.fromTime, oth.toTime, oth.to); + } + }; + +//---------------------------------------------------------------------------- + + CTeleport & Add ( const string & from, + const string & to, + unsigned fromTime, + unsigned toTime ) + { + auto it1 = _toInt.try_emplace(from, City(_toInt.size())); + if (it1.second) _ports.emplace_back(); + + auto it2 = _toInt.try_emplace(to, City(_toInt.size())); + if (it2.second) _ports.emplace_back(); + + _ports[ it1.first->second ].emplace(it2.first->second, Time(fromTime), Time(toTime)); + + return *this; + } + +//---------------------------------------------------------------------------- + + CTeleport & Optimize ( void ) + { + // todo + return *this; + } + +//---------------------------------------------------------------------------- + + unsigned FindWay( const string & from, const string & to, unsigned time ) { + std::queue q; + std::vector