Go to diff to previous submission
#include <stdlib.h> #include <stdio.h> int pole[200][200]; int posSx, posSy; int posFx, posFy; int sizex, sizey; void check(int x, int y, int jump) { if(x > -1 && y > -1 && x < 200 && y < 200) { if(pole[x][y]>jump) { pole[x][y] = jump; check(x+2, y+1,jump+1); check(x+2, y-1,jump+1); check(x-2, y+1,jump+1); check(x-2, y-1,jump+1); check(x+1, y+2,jump+1); check(x+1, y-2,jump+1); check(x-1, y+2,jump+1); check(x-1, y-2,jump+1); } } } bool backt; void back(int x, int y, int num) { if(x > 100 - posSx && y > 100 - posSy && x < 100 - posSx + sizex && y < 100 - posSy + sizey) { if(pole[x][y] == num) { if(num == 0) backt = true; else { back(x+2, y+1,num-1); back(x+2, y-1,num-1); back(x-2, y+1,num-1); back(x-2, y-1,num-1); back(x+1, y+2,num-1); back(x+1, y-2,num-1); back(x-1, y+2,num-1); back(x-1, y-2,num-1); } } } } int main(void) { for(int i = 0; i<200; i++) for(int j = 0; j<200; j++) pole[i][j] = 1000; check(100, 100, 0); while(scanf("%d %d %d %d %d %d", &sizex, &sizey, &posSx, &posSy, &posFx, &posFy) == 6) { backt = false; back(posFx - posSx + 100, posFy + 100 - posSy, pole[posFx - posSx + 100][posFy + 100 - posSy]); if(backt) printf("%d\n", pole[posFx - posSx + 100][posFy + 100 - posSy]); else printf("impossible\n"); } return 0; }
--- c4.s1193.cteam107.grasshop.cpp.0.grassshop.cpp +++ c4.s1286.cteam107.grasshop.cpp.0.grassshop.cpp @@ -2,5 +2,5 @@ #include <stdio.h> -int pole[100][100]; +int pole[200][200]; int posSx, posSy; int posFx, posFy; @@ -9,12 +9,9 @@ void check(int x, int y, int jump) { - if(jump > sizex * 3/2 && jump > sizey * 3/2) - return; - if(x > -1 && y > -1 && x < sizex && y < sizey) + if(x > -1 && y > -1 && x < 200 && y < 200) { if(pole[x][y]>jump) -{ + { pole[x][y] = jump; - check(x+2, y+1,jump+1); check(x+2, y-1,jump+1); @@ -32,29 +29,49 @@ } +bool backt; +void back(int x, int y, int num) +{ + if(x > 100 - posSx && y > 100 - posSy && x < 100 - posSx + sizex && y < 100 - posSy + sizey) + { + if(pole[x][y] == num) + { + if(num == 0) + backt = true; + else + { + back(x+2, y+1,num-1); + back(x+2, y-1,num-1); + back(x-2, y+1,num-1); + back(x-2, y-1,num-1); + back(x+1, y+2,num-1); + back(x+1, y-2,num-1); + back(x-1, y+2,num-1); + back(x-1, y-2,num-1); + } + + } + } + +} + + int main(void) { + for(int i = 0; i<200; i++) + for(int j = 0; j<200; j++) + pole[i][j] = 1000; + + check(100, 100, 0); while(scanf("%d %d %d %d %d %d", &sizex, &sizey, &posSx, &posSy, &posFx, &posFy) == 6) { - for(int i = 0; i<sizex; i++) - for(int j = 0; j<sizey; j++) - pole[i][j] = 1000; - - check(posSx-1, posSy-1, 0); - - - /*for(int i = 0; i<sizex; i++) - { - for(int j = 0; j<sizey; j++) - printf("%d", pole[i][j]); - printf("\n"); - }*/ - - - if(pole[posFx-1][posFy-1]==1000) - printf("impossible\n"); + backt = false; + back(posFx - posSx + 100, posFy + 100 - posSy, pole[posFx - posSx + 100][posFy + 100 - posSy]); + if(backt) + printf("%d\n", pole[posFx - posSx + 100][posFy + 100 - posSy]); else - printf("%d\n", pole[posFx-1][posFy-1]); + printf("impossible\n"); + }