Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <queue>
- #include <map>
- #include <set>
- #include <bitset>
- using namespace std;
- typedef long long ll;
- struct bf{
- int v, u, c;
- };
- int main() {
- int a, b, v, u, c;
- cin >> a >> b;
- int rx = a;
- int ry = b;
- map<pair<int, int>, int> m;
- queue<bf> q;
- q.push({0, 0, 0});
- vector<pair<int, int>> move = {{-1, 2}, {-1, -2}, {1, 2}, {1, -2},{2, -1}, {2, 1}, {-2, -1}, {-2, 1}};
- while(v != a || u != b){
- v = q.front().v;
- u = q.front().u;
- c = q.front().c;
- q.pop();
- for(int i = 0; i < 8; ++i){
- if(!m.count({v + move[i].first, u + move[i].second}) && v + move[i].first - a - (v - a) < 2 /*&& u + move[i].second - b - (u - b) < 2*/){
- m[{v + move[i].first, u + move[i].second}] = c + 1;
- q.push({v + move[i].first, u + move[i].second, c + 1});
- }
- }
- }
- c = 1e9;
- vector<pair<int, int>> ans;
- while(a != 0 || b != 0){
- int x = 0;
- int y = 0;
- for(int i = 0; i < 8; ++i){
- if(m[{a + move[i].first, b + move[i].second}] > 0 && m[{a + move[i].first, b + move[i].second}] < c){
- x = a + move[i].first;
- y = b + move[i].second;
- c = m[{a + move[i].first, b + move[i].second}];
- }
- }
- a = x;
- b = y;
- ans.push_back({a, b});
- }
- for(int i = 1; i < ans.size(); ++i){
- cout << ans[ans.size() - i - 1].first << " " << ans[ans.size() - i - 1].second << "\n";
- }
- cout << rx << " " << ry << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement