Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unordered_map>
- #include <string>
- #include <vector>
- #include <iostream>
- #include <set>
- #include <queue>
- #include "optimization.h"
- using namespace std;
- vector<vector<int>> matrix;
- vector<bool> used;
- int answer = 0;
- int n, m;
- string f, s;
- string f_o, s_o;
- vector<pair<int, int>> moves = {{ -1, 2 },
- { 1, 2 },
- { 2, 1 },
- { 2, -1 },
- { 1, -2 },
- { -1, -2 },
- { -2, -1 },
- { -2, 1 },};
- unordered_map<string, bool> used1, used2;
- unordered_map<string, string> was;
- auto id(string a, string b) {
- return was[a + b];
- }
- vector<string>result;
- void bfs() {
- queue<pair<string, string>> q;
- q.push({f, s});
- while (!q.empty()) {
- auto[m1_s, m2_s] = q.front();
- q.pop();
- string m1 = m1_s;
- string m2 = m2_s;
- if (m1 == f_o && m2 == s_o) {
- auto y = m1+m2;
- while (y != f+s) {
- auto t = was[y];
- if (t.substr(0,2) == y.substr(0,2)){
- result.push_back("2 " + y.substr(2));
- }
- else{
- result.push_back("1 "+ y.substr(0,2));
- }
- y = t;
- }
- return;
- }
- for (auto[x, y]: moves) {
- m1 = m1_s; m2 = m2_s;
- m1[0] += x; m1[1] += y;
- if (m1 != m2 && m1[0] <= 'h' && m1[0] >= 'a' && m1[1] <= '8' && m1[1] >= '1' && !used1[m1 + m2]) {
- was[m1 + m2] = m1_s+m2_s;
- q.push({m1, m2});
- used1[m1+m2] = true;
- }
- m1 = m1_s;
- m2[0] += x; m2[1] += y;
- if (m1 != m2 && m2[0] <= 'h' && m2[0] >= 'a' && m2[1] <= '8' && m2[1] >= '1' && !used1[m1+m2]) {
- was[m1 + m2] = m1_s + m2_s;
- q.push({m1, m2});
- used1[m1+m2] = true;
- }
- m2 = m2_s;
- }
- }
- }
- int main() {
- cin >> f >> s;
- cin >> f_o >> s_o;
- bfs();
- for (int i = result.size()-1;i >= 0;i--){
- cout << result[i] << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement