Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- typedef long long ll;
- using namespace std;
- int a, b;
- int main() {
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- cin >> a >> b;
- vector<pair<int, int>> res = {{a, b}};
- while (a != 0 && abs(a) >= 5 && abs(b) >= 5){
- if (a < 0){
- if (a == -1){
- if (b > 0){
- a++;
- b-=2;
- }
- else{
- a++;
- b += 2;
- }
- }
- else{
- if (b > 0){
- a+= 2;
- b--;
- }
- else{
- a += 2;
- b++;
- }
- }
- }
- else{
- if(a == 1){
- if (b > 0){
- a--;
- b -= 2;
- }
- else{
- a--;
- b += 2;
- }
- }
- else{
- if (b > 0){
- a -= 2;
- b--;
- }
- else{
- a -= 2;
- b++;
- }
- }
- }
- res.emplace_back(a, b);
- }
- while (b != 0 && abs(a) >= 5 && abs(b) >= 5){
- if (b > 0){
- if (b == 1){
- if (a > 0){
- a -= 2;
- b--;
- }
- else {
- a += 2;
- b--;
- }
- }
- else {
- if (a > 0){
- a--;
- b-= 2;
- }
- else {
- a++;
- b -= 2;
- }
- }
- }
- else{
- if (b == -1){
- if (a > 0){
- a -= 2;
- b++;
- }
- else{
- a += 2;
- b++;
- }
- }
- else{
- if (a > 0){
- a--;
- b += 2;
- }
- else {
- a++;
- b+= 2;
- }
- }
- }
- res.emplace_back(a, b);
- }
- const int A = 8;
- a += A; b += A;
- vector<vector<int>> d(2*A, vector<int>(2*A, INT_MAX));
- vector<vector<pair<int, int>>> path(2*A, vector<pair<int, int>>(2*A, {-1, -1}));
- queue<pair<int, int>> q;
- vector<pair<int, int>> moves = {{2, 1}, {2, -1}, {1, 2}, {1, -2}, {-2, 1}, {-2, -1}, {-1, 2}, {-1, -2}};
- d[a][b] = 0;
- q.push({a, b});
- while (!q.empty() && d[A][A] == INT_MAX){
- pair<int, int> p = q.back();
- q.pop();
- for (pair<int, int> &t1 : moves){
- pair<int, int> m = {p.first+t1.first, p.second + t1.second};
- if (m.first >= 0 && m.first < 2*A && m.second >= 0 && m.second < 2*A){
- if (d[m.first][m.second] > d[p.first][p.second] + 1){
- d[m.first][m.second] = d[p.first][p.second] + 1;
- path[m.first][m.second] = p;
- q.push(m);
- }
- }
- }
- }
- vector<pair<int, int>> tmp;
- pair<int, int> p = {A, A};
- while (path[p.first][p.second] != make_pair(-1, -1)){
- tmp.emplace_back(p.first - A, p.second-A);
- p = path[p.first][p.second];
- }
- reverse(tmp.begin(), tmp.end());
- for (int i = 0; i < tmp.size(); ++i){
- res.emplace_back(tmp[i].first, tmp[i].second);
- }
- reverse(res.begin(), res.end());
- for (int i = 1; i < res.size(); ++i){
- cout << res[i].first << ' ' << res[i].second << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement