TOXIC_S.PAS 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. {$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q-,R-,S+,T-,V+,X+,Y+}
  2. {$M 65520,0,655360}
  3. program Toxic; {Search Arithmetic}
  4. {JP 2000-1-11}
  5. const
  6. fin = 'toxic.in';
  7. fon = 'toxic.out';
  8. Dir : array[1..6,1..3]of shortint =
  9. ((1,0,0), (-1,0,0),
  10. (0,1,0), (0,-1,0),
  11. (0,0,1), (0,0,-1));
  12. Max = 10;
  13. type
  14. T2D = array[0..max+1,0..max+1]of shortint;
  15. T3D = array[0..max+1]of t2d;
  16. var
  17. Block, Adjoin : t3d;
  18. n : array[1..3]of integer;
  19. a,aa : array[1..1000]of char;
  20. o,oo : array[1..1000,1..3]of integer;
  21. l,ll, E,ee : integer;
  22. procedure DataIn;
  23. var f:text;
  24. begin
  25. assign(f,fin); reset(f);
  26. readln(f,n[1],n[2],n[3]);
  27. close(f);
  28. end;
  29. procedure Refresh(x,y,z:integer;r:shortint);
  30. var i,xx,yy,zz:integer;
  31. begin
  32. for i:=1 to 6 do
  33. begin
  34. xx:=x+dir[i,1]; yy:=y+dir[i,2]; zz:=z+dir[i,3];
  35. inc(adjoin[xx,yy,zz],r);
  36. end;
  37. end;
  38. procedure Search(x,y,z:integer);
  39. var i,
  40. xx,yy,zz : integer;
  41. begin
  42. {Eat}
  43. for i:=1 to 6 do
  44. begin
  45. xx:=x+dir[i,1]; yy:=y+dir[i,2]; zz:=z+dir[i,3];
  46. if (xx=0)or(xx=n[1]+1)or(yy=0)or(yy=n[2]+1)or(zz=0)or(zz=n[3]+1)
  47. then continue;
  48. if (block[xx,yy,zz]=0) and (adjoin[xx,yy,zz]=1) then
  49. begin
  50. block[xx,yy,zz]:=1;
  51. refresh(xx,yy,zz,1);
  52. inc(l); a[l]:='E';
  53. o[l,1]:=xx; o[l,2]:=yy; o[l,3]:=zz;
  54. inc(e);
  55. if e > ee then
  56. begin
  57. ee:=e; aa:=a; oo:=o; ll:=l;
  58. end;
  59. search(x,y,z);
  60. dec(l);
  61. dec(e);
  62. refresh(xx,yy,zz,-1);
  63. block[xx,yy,zz]:=0;
  64. end;
  65. end;
  66. {Move}
  67. for i:=1 to 6 do
  68. begin
  69. xx:=x+dir[i,1]; yy:=y+dir[i,2]; zz:=z+dir[i,3];
  70. if (block[xx,yy,zz]=1) {and (adjoin[xx,yy,zz]=1)} then
  71. begin
  72. block[xx,yy,zz]:=2;
  73. inc(l); a[l]:='M';
  74. o[l,1]:=xx; o[l,2]:=yy; o[l,3]:=zz;
  75. search(xx,yy,zz);
  76. dec(l);
  77. block[xx,yy,zz]:=1;
  78. end;
  79. end;
  80. end;
  81. procedure out;
  82. var f:text;
  83. i:integer;
  84. begin
  85. assign(f,fon); rewrite(f);
  86. for i:=1 to ll do
  87. writeln(f,aa[i],' ',oo[i,1],' ',oo[i,2],' ',oo[i,3]);
  88. close(f);
  89. end;
  90. begin
  91. datain; e:=1;
  92. l:=2; a[1]:='E'; a[2]:='M';
  93. o[1,1]:=1; o[1,2]:=1; o[1,3]:=1;
  94. o[2,1]:=1; o[2,2]:=1; o[2,3]:=1;
  95. block[1,1,1]:=2; refresh(1,1,1,1);
  96. search(1,1,1);
  97. out;
  98. end.