比这篇新的文章:
range.right.cpp
比这篇旧的文章: range.pas
作者: xpycc, 点击229次, 评论(0), 收藏者(0)
打分:
所有评论,共0条:( 我也来说两句)
比这篇旧的文章: range.pas
range.pas
语言: Delphi, 标签: 无 2008/08/22发布 3个月前更新作者: xpycc, 点击229次, 评论(0), 收藏者(0)
Delphi语言: range.pas
01 program range;
02 const
03 maxn=250;
04 var
05 fin,fout:text;
06 map:array[1..maxn,1..maxn]ofboolean;
07 n,size,i,j,count:longint;
08 c:char;
09 begin
10 assign(fin,'range.in');
11 reset(fin);
12 readln(fin,n);
13 for i:=1 to n do begin
14 for j:=1 ton do begin
15 read(fin,c);
16 if c='1' then map[i,j]:=true else map[i,j]:=false;
17 //这个时候k的大小为1
18 end;
19 readln(fin);
20 end;
21 close(fin);
22
23 assign(fout,'range.out'); rewrite(fout);
24 for size:=2 to n do begin //这里的size就是我说的k
25 count:=0;
26 for i:=1 ton+1-size do
27 for j:=1 to n+1-size do begin
28 map[i,j]:=map[i,j] and map[i,j+1] and map[i+1,j] and map[i+1,j+1];
29 //状态转移:注意:=左边的东西表示大小为k,右边的表示的大小为k-1
30 if map[i,j] then inc(count);
31 end;
32 if count>0 then writeln(fout,size,'',count);
33 if count<4 then break;
34 //更具状态转移可知,1个大小为k+1的矩形存在,就必须有4个大小为k的矩形存在
35 end;
36 close(fout);
37 end.
02 const
03 maxn=250;
04 var
05 fin,fout:text;
06 map:array[1..maxn,1..maxn]ofboolean;
07 n,size,i,j,count:longint;
08 c:char;
09 begin
10 assign(fin,'range.in');
11 reset(fin);
12 readln(fin,n);
13 for i:=1 to n do begin
14 for j:=1 ton do begin
15 read(fin,c);
16 if c='1' then map[i,j]:=true else map[i,j]:=false;
17 //这个时候k的大小为1
18 end;
19 readln(fin);
20 end;
21 close(fin);
22
23 assign(fout,'range.out'); rewrite(fout);
24 for size:=2 to n do begin //这里的size就是我说的k
25 count:=0;
26 for i:=1 ton+1-size do
27 for j:=1 to n+1-size do begin
28 map[i,j]:=map[i,j] and map[i,j+1] and map[i+1,j] and map[i+1,j+1];
29 //状态转移:注意:=左边的东西表示大小为k,右边的表示的大小为k-1
30 if map[i,j] then inc(count);
31 end;
32 if count>0 then writeln(fout,size,'',count);
33 if count<4 then break;
34 //更具状态转移可知,1个大小为k+1的矩形存在,就必须有4个大小为k的矩形存在
35 end;
36 close(fout);
37 end.
所有评论,共0条:( 我也来说两句)
代码