Dennnhhhickk

Untitled

Oct 2nd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. SysUtils;
  7.  
  8. const
  9. MAXIN = 9;
  10.  
  11. var
  12. x, y, x1, y1, k, min, first_int, x2, y2: integer;
  13. a: array [0..MAXIN, 0..MAXIN] of integer;
  14. bol: array [0..MAXIN, 0..MAXIN] of boolean;
  15.  
  16. procedure clean();
  17. var
  18. i, j: integer;
  19. begin
  20. for i := 1 to MAXIN do
  21. for j := 1 to MAXIN do
  22. begin
  23. a[i][j] := 0;
  24. bol[i][j] := true;
  25. end;
  26. end;
  27.  
  28. procedure rec(x, y: integer);
  29. begin
  30. if (x in [0..9]) and (y in [0..9]) and (bol[x][y]) then
  31. begin
  32. bol[x][y] := false;
  33. if (x = x1) and (y = y1) then
  34. if (min < first_int) then
  35. begin
  36. k := 1;
  37. first_int := min;
  38. writeln(x, ' ', y);
  39. end
  40. else
  41. if (min = first_int) then
  42. inc(k)
  43. else
  44. else
  45. begin
  46. inc(min);
  47. rec(x + 2, y + 1);
  48. rec(x + 2, y - 1);
  49. rec(x - 2, y + 1);
  50. rec(x - 2, y - 1);
  51. rec(x + 1, y + 2);
  52. rec(x + 1, y - 2);
  53. rec(x - 1, y + 2);
  54. rec(x - 1, y - 2);
  55. end;
  56. end;
  57. end;
  58.  
  59. begin
  60. readln(x2, y2, x1, y1);
  61. clean();
  62. min := 0;
  63. first_int := MAXINT;
  64. a[x2][y2] := 1;
  65. k := 1;
  66. rec(x2, y2);
  67. if (k <> 0) then
  68. writeln(k, ' ', first_int)
  69. else
  70. writeln(-1);
  71. readln;
  72. readln;
  73. end.
Advertisement
Add Comment
Please, Sign In to add comment