From a3dd2581ed4847670f81157091016c14ca18803d Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Tue, 14 Jan 2020 18:29:11 +0700 Subject: [usth/MATH2.3] Mathemate Discretely --- usth/MATH2.3/5/turing.cc | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 usth/MATH2.3/5/turing.cc (limited to 'usth/MATH2.3/5/turing.cc') diff --git a/usth/MATH2.3/5/turing.cc b/usth/MATH2.3/5/turing.cc new file mode 100644 index 0000000..7ef5deb --- /dev/null +++ b/usth/MATH2.3/5/turing.cc @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +using namespace std; + +int +main () +{ + int n; + unordered_map>> tuples; + cin >> n; + while (n--) + { + int s, x, t, y, d; + cin >> s >> x >> t >> y >> d; + tuples[s][x] = {t, y, d}; + } + + deque input; + cin >> n; + while (n--) + { + int i; + cin >> i; + input.push_back (i); + } + + int o {0}, i {0}, s {0}, x, d; + for (;;) + { + tie (s, x, d) = tuples[s][input[i - o]]; + if (!d) + break; + + if (i < o) + { + input.push_front (x); + o++; + } + else if (i - o == input.size ()) + input.push_back (x); + else + input[i - o] = x; + + if (d < 0) + i--; + else + i++; + } + + for (auto const& i : input) + cout << i; + cout << endl; +} -- cgit 1.4.1