记录编号 41354 评测结果 AAAAAAAA
题目名称 劣质的草 最终得分 100
用户昵称 GravatarFangel 是否通过 通过
代码语言 Pascal 运行时间 0.142 s
提交时间 2012-07-22 11:50:17 内存使用 11.61 MiB
显示代码纯文本
  1. var
  2. a,b,c,d,m,n,i,j:longint;
  3. ss:array[1..1000,1..1000] of longint;
  4. line:array[0..999999,1..2] of longint;
  5. //-----------------------------------------------------------------------
  6. procedure lin(x,y:longint);
  7. begin
  8. inc(j);
  9. line[j,1]:=x;
  10. line[j,2]:=y;
  11. end;
  12. //-----------------------------------------------------------------------
  13. procedure lout(var x,y:longint);
  14. begin
  15. inc(i);
  16. x:=line[i,1];
  17. y:=line[i,2];
  18. end;
  19. //-----------------------------------------------------------------------
  20. procedure flood(x,y:longint);
  21. begin
  22. fillchar(line,sizeof(line),0);
  23. ss[x,y]:=0;
  24. lin(x,y);
  25. while i<j do
  26. begin
  27. lout(x,y);
  28. if (y>1) and (ss[x,y-1]>0) then begin ss[x,y-1]:=0;lin(x,y-1);end;
  29. if (y>1) and (x>1) and (ss[x-1,y-1]>0) then begin ss[x-1,y-1]:=0;lin(x-1,y-1);end;
  30. if (x>1) and (ss[x-1,y]>0) then begin ss[x-1,y]:=0;lin(x-1,y);end;
  31. if (x>1) and (y<n) and (ss[x-1,y+1]>0) then begin ss[x-1,y+1]:=0;lin(x-1,y+1);end;
  32. if (y<n) and (ss[x,y+1]>0) then begin ss[x,y+1]:=0;lin(x,y+1);end;
  33. if (y<n) and (x<m) and (ss[x+1,y+1]>0) then begin ss[x+1,y+1]:=0;lin(x+1,y+1);end;
  34. if (x<m) and (ss[x+1,y]>0) then begin ss[x+1,y]:=0;lin(x+1,y);end;
  35. if (x<m) and (y>1) and (ss[x+1,y-1]>0) then begin ss[x+1,y-1]:=0;lin(x+1,y-1);end;
  36.  
  37. end;
  38. end;
  39. //-----------------------------------------------------------------------
  40. begin
  41. assign(input,'badgras.in');
  42. reset(input);
  43. assign(output,'badgras.out');
  44. rewrite(output);
  45. read(m,n);
  46. for a:=1 to m do
  47. for b:=1 to n do
  48. read(ss[a,b]);
  49. for a:=1 to m do
  50. for b:=1 to n do
  51. if ss[a,b]>0 then
  52. begin
  53. inc(c);
  54. flood(a,b);
  55. end;
  56. write(c);
  57. close(input);
  58. close(output);
  59. end.