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;
- 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})){
- m[{v + move[i].first, u + move[i].second}] = c;
- q.push({v + move[i].first, u + move[i].second, c + 1});
- }
- }
- }
- while(a != 0 || b != 0){
- int c = 1e9;
- int x = 0;
- int y = 0;
- for(int i = 0; i < 8; ++i){
- if(m[{a + move[i].first, b + move[i].second}] < c && m[{a + move[i].first, b + move[i].second}] > 0){
- x = a + move[i].first;
- y = b + move[i].second;
- }
- }
- a = x;
- b = y;
- cout << a << " " << b << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement