3406: [Usaco2009 Oct]Invasion of the Milkweed 乳草的入侵
Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 87 Solved: 49
[Submit][Status][Discuss]
Description
Input
第1行:4个由空格隔开的整数X,K Mx,My.
第2到第Y+1行:每行由X个字符描述草地.
Output
一个单独的整数表示最后一个不是大石块的格子被乳草占领的星期数
Sample Input
4 3 1 1
....
..*.
.**.
....
..*.
.**.
Sample Output
4
HINT
Source
题解:题目本身很水,一道灌水法,BFS秒杀
但还是WA了一下,表示题目描述简直坑爹不解释,注意看清题目描述再下手(还有OI经常很良心的让你就算题目理解错了也能过样例TT)
1 /************************************************************** 2 Problem: 3406 3 User: HansBug 4 Language: Pascal 5 Result: Accepted 6 Time:20 ms 7 Memory:444 kb 8 ****************************************************************/ 9 10 const dir:array[1..8,1..2] of longint=((1,0),(-1,0),(0,1),(0,-1),(1,1),(-1,-1),(-1,1),(1,-1)); 11 var 12 i,j,k,l,m,n,x,y,x0,y0,f,r:longint; 13 a:array[0..101,0..101] of longint; 14 d:array[0..15000,1..3] of longint; 15 ch:char; 16 begin 17 readln(m,n,y,x);x:=n+1-x; 18 for i:=0 to n+1 do 19 begin 20 a[i,m+1]:=1; 21 a[i,0]:=1; 22 end; 23 for i:=0 to m+1 do 24 begin 25 a[n+1,i]:=1; 26 a[0,i]:=1; 27 end; 28 for i:=1 to n do 29 for j:=1 to m do 30 begin 31 read(ch); 32 if ch='.' then a[i,j]:=0 else a[i,j]:=1; 33 if j=m then readln; 34 end; 35 d[1,1]:=x;d[1,2]:=y;d[1,3]:=0;f:=1;r:=2; 36 while f<r do 37 begin 38 for i:=1 to 8 do 39 begin 40 x0:=d[f,1]+dir[i,1]; 41 y0:=d[f,2]+dir[i,2]; 42 if a[x0,y0]=0 then 43 begin 44 d[r,1]:=x0; 45 d[r,2]:=y0; 46 d[r,3]:=d[f,3]+1; 47 inc(r);a[x0,y0]:=1; 48 end; 49 end; 50 inc(f); 51 end; 52 writeln(d[f-1,3]); 53 readln; 54 end.