Source code for submission s685

Go to diff to previous submission

grasshop.c

  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int R,C, Lr, Lc, Gr, Gc;
  5.  
  6. int get_dist(int a, int b, int x, int y)
  7. {
  8. return fabs(x-a) + fabs(y-b);
  9. }
  10.  
  11. int main()
  12. {
  13. while(scanf("%d %d %d %d %d %d", &R,&C,&Gr,&Gc,&Lr,&Lc) == 6)
  14. {
  15. int d = get_dist(Gr, Gc, Lr, Lc);
  16. if (d == 0) {
  17. printf("0\n");
  18. }
  19. else if (R == 1 || C == 1) {
  20. printf("impossible\n");
  21. }
  22. else if (R == 2 || C == 2) {
  23. if (d % 3 == 0) {
  24. printf("%d\n", d/3);
  25. } else printf("impossible\n");
  26. } else {
  27. switch(d) {
  28. case 1:
  29. printf("3\n");
  30. break;
  31. case 2:
  32. printf("2\n");
  33. break;
  34. case 3:
  35. printf("1\n");
  36. break;
  37. case 4:
  38. printf("4\n");
  39. break;
  40. case 5:
  41. printf("3\n");
  42. break;
  43. }
  44. if (d > 5) {
  45. int result = (d % 3) > 0 ? 1 : 0;
  46. result += d/3;
  47. printf("%d\n", result);
  48. }
  49. }
  50. }
  51. return 0;
  52. }
  53.  

Diff to submission s678

grasshop.c

--- c4.s678.cteam074.grasshop.c.0.grasshop.c
+++ c4.s685.cteam074.grasshop.c.0.grasshop.c
@@ -14,5 +14,8 @@
         {
                 int d = get_dist(Gr, Gc, Lr, Lc);
-                if (R == 1 || C == 1) {
+                if (d == 0) {
+                        printf("0\n");
+                }
+                else if (R == 1 || C == 1) {
                         printf("impossible\n");
                 }