Source code for submission s622

Go to diff to previous submission

grasshop.c

  1. #include <stdio.h>
  2.  
  3. int Pole[201][201];
  4.  
  5. int FrontaX[100*100*20];
  6. int FrontaY[100*100*20];
  7. int Zac,Kon;
  8. int R,C,Gr,Gc,Lr,Lc,Cc,Cr,T;
  9. int Found;
  10.  
  11. void Skoc(int X, int Y, int Time) {
  12. //printf("> %d %d %d\n",X,Y,Time);
  13. if ((X<1) || (X>R) || (Y<1) || (Y>C)) return;
  14. if ((Pole[X][Y] > Time) || (Pole[X][Y] == -1)) {
  15. Pole[X][Y]=Time;
  16. FrontaX[++Kon]=X;
  17. FrontaY[Kon]=Y;
  18. if ((X == Lr) && (Y == Lc)) Found = 1;
  19. };
  20. };
  21.  
  22. int main() {
  23. int x,y;
  24.  
  25. while (scanf("%d%d%d%d%d%d",&R,&C,&Gr,&Gc,&Lr,&Lc)==6) {
  26. for (x=0;x<=R;x++) for (y=0;y<=C;y++) Pole[x][y]=-1;
  27. if ((Gr==Lr) && (Gc == Lc)) {
  28. printf("0\n");
  29. } else {
  30. FrontaX[0]=Gr;
  31. FrontaY[0]=Gc;
  32. Zac=0;
  33. Kon=0;
  34. Found=0;
  35. Pole[Gr][Gc]=0;
  36. while ((Zac<=Kon) && (Found==0)) {
  37. Cr = FrontaX[Zac];
  38. Cc = FrontaY[Zac++];
  39. T = Pole[Cc][Cr];
  40. //printf("%d %d %d %d %d\n",Cc,Cr,T,Zac,Kon);
  41. Skoc(Cr+2,Cc+1,T+1);
  42. Skoc(Cr+2,Cc-1,T+1);
  43. Skoc(Cr-2,Cc+1,T+1);
  44. Skoc(Cr-2,Cc-1,T+1);
  45. Skoc(Cr+1,Cc+2,T+1);
  46. Skoc(Cr+1,Cc-2,T+1);
  47. Skoc(Cr-1,Cc+2,T+1);
  48. Skoc(Cr-1,Cc-2,T+1);
  49. };
  50. if (Pole[Lr][Lc] == -1) {
  51. printf("impossible\n");
  52. } else {
  53. printf("%d\n",Pole[Lr][Lc]);
  54. };
  55. };
  56. };
  57. return 0;
  58. };
  59.  

Diff to submission s620

grasshop.c

--- c4.s620.cteam048.grasshop.c.0.grasshop.c
+++ c4.s622.cteam048.grasshop.c.0.grasshop.c
@@ -35,6 +35,6 @@
                         Pole[Gr][Gc]=0;
                         while ((Zac<=Kon) && (Found==0)) {
-                                Cc = FrontaX[Zac];
-                                Cr = FrontaY[Zac++];
+                                Cr = FrontaX[Zac];
+                                Cc = FrontaY[Zac++];
                                 T = Pole[Cc][Cr];
 //printf("%d %d %d %d %d\n",Cc,Cr,T,Zac,Kon);