记录编号 14696 评测结果 AAAAAAAAAAA
题目名称 [USACO Oct09] 乳草的入侵 最终得分 100
用户昵称 Gravatarybh 是否通过 通过
代码语言 Pascal 运行时间 0.038 s
提交时间 2009-11-03 14:26:24 内存使用 0.14 MiB
显示代码纯文本
  1. program milkweek;
  2. const
  3. weiyi:array[1..8,1..2] of integer=
  4. ((1,0),(0,1),(-1,0),(0,-1),(1,1),(-1,-1),(-1,1),(1,-1));
  5. var
  6. a:array[0..101,0..101] of char;
  7. f:array[0..101,0..101] of integer;
  8. x,y,mx,my,i,j,k,s1,s,step,i1,j1:integer;
  9. bool:boolean;
  10. begin
  11. assign(input,'milkweed.in');
  12. reset(input);
  13. assign(output,'milkweed.out');
  14. rewrite(output);
  15. readln(x,y,mx,my);
  16. for i:=1 to y do
  17. begin
  18. for j:=1 to x do
  19. begin
  20. read(a[i,j]);
  21. if a[i,j]='.'
  22. then inc(s1)
  23. end;
  24. readln
  25. end;
  26. if (x=1) and (y=1) then
  27. begin
  28. if a[1,1]='.'
  29. then writeln(0)
  30. else writeln(-1);
  31. close(input);
  32. close(output);
  33. halt
  34. end;
  35. fillchar(f,sizeof(f),0);
  36. f[y+1-my,mx]:=1;
  37. s:=1;
  38. step:=1;
  39. repeat
  40. bool:=true;
  41. inc(step);
  42. for i:=1 to y do
  43. for j:=1 to x do
  44. if f[i,j]=step-1 then
  45. begin
  46. for k:=1 to 8 do
  47. begin
  48. i1:=i+weiyi[k,1];
  49. j1:=j+weiyi[k,2];
  50. if (i1>=1) and (i1<=y) and (j1>=1) and (j1<=x) then
  51. begin
  52. if (a[i1,j1]='.') and (f[i1,j1]=0) then
  53. begin
  54. bool:=false;
  55. f[i1,j1]:=step;
  56. inc(s)
  57. end
  58. end
  59. end
  60. end
  61. until (s=s1) or bool;
  62. if bool
  63. then writeln(-1)
  64. else writeln(step-1);
  65. close(input);
  66. close(output)
  67. end.