Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <cmath>
- #include <algorithm>
- #include <iomanip>
- #include <queue>
- #include <stack>
- #include <climits>
- using namespace std;
- struct horse {
- long x, y, l;
- };
- void print(horse* onewhitehorse, long v) {
- if (v > -1)
- {
- print(onewhitehorse, onewhitehorse[v].l);
- cout << onewhitehorse[v].x << " " << onewhitehorse[v].y<<endl;
- }
- }
- int main() {
- // freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- int x[8] = { 1,2,2,1,-1,-2,-2,-1 };
- int y[8] = { 2,1,-1,-2,-2,-1,1,2 };
- long area[50][50]{};
- bool end = false;
- int s = 1, klv = 0, v = 0, u = 0, k = 0;
- horse one[1000];
- long n, m, x2, y2;
- cin >> n >> m >> one[0].x >> one[0].y >> x2 >> y2;
- one[0].l = -1;
- do {
- end = false;
- for (int i = k; v != 0 && i <= u; i++) {
- for (int j = 0; j < 8; j++) {
- long y1 = one[i].y + y[j];
- long x1 = one[i].x + x[j];
- if (x1 < 1 || y1 < 1 || area[x1][y1] != 0 || x1 > n || y1 > m) continue;
- else{
- end = true;
- area[x1][y1]++;
- one[s].l = i;
- one[s].x = x1; one[s].y = y1;
- s++;
- if (x1 == x2 && y1 == y2){
- v = s - 1; break;
- }
- }
- }
- }
- klv++;
- k = u + 1;
- u = s - 1;
- } while (v != 0 && end == true);
- if (v != 0) {
- cout << klv << endl;
- print(one, v);
- }
- else cout << "-1";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement