标签:
6 8
.....#.#
##.....#
##.....#
.......#
#......#
#..#...#
There are 5 ships.
1 var 2 i,j,k,l,m,n,tt:longint; 3 a,b,dow,up,lef,rig:array[0..1050,0..1050] of longint; 4 c1:char; 5 procedure OrzPhile; 6 begin 7 writeln(‘Bad placement.‘); 8 halt; 9 end; 10 begin 11 readln(n,m); 12 for i:=1 to n do 13 begin 14 for j:=1 to m do 15 begin 16 read(c1); 17 case c1 of 18 ‘.‘:a[i,j]:=0; 19 else a[i,j]:=1; 20 end; 21 end; 22 readln; 23 end; 24 fillchar(b,sizeof(b),0); 25 fillchar(dow,sizeof(dow),0); 26 fillchar(rig,sizeof(rig),0); 27 fillchar(lef,sizeof(lef),0); 28 for i:=1 to n do 29 for j:=1 to m do 30 begin 31 if a[i,j]=1 then lef[i,j]:=lef[i,j-1]+1 else lef[i,j]:=0; 32 if a[i,j]=1 then up[i,j]:=up[i-1,j]+1 else up[i,j]:=0; 33 end; 34 for i:=n downto 1 do 35 for j:=m downto 1 do 36 begin 37 if a[i,j]=1 then rig[i,j]:=rig[i,j+1]+1 else rig[i,j]:=0; 38 if a[i,j]=1 then dow[i,j]:=dow[i+1,j]+1 else dow[i,j]:=0; 39 end; 40 tt:=0; 41 for i:=1 to n do 42 for j:=1 to m do 43 if (a[i,j]=1) and (a[i-1,j]=0) and (a[i,j-1]=0) then 44 begin 45 for k:=1 to dow[i,j] do 46 begin 47 if lef[i+k-1,j]>1 then OrzPhile; 48 if rig[i+k-1,j]<>rig[i,j] then OrzPhile; 49 end; 50 for k:=1 to rig[i,j] do 51 begin 52 if up[i,j+k-1]>1 then OrzPhile; 53 if dow[i,j+k-1]<>dow[i,j] then OrzPhile; 54 end; 55 inc(tt); 56 end; 57 writeln(‘There are ‘,tt,‘ ships.‘); 58 end. 59
标签:
原文地址:http://www.cnblogs.com/HansBug/p/4175784.html