PersonalCorpus 版 (精华区)

277461 03:18:32 15 Nov 2002 Big Guava
1221 Pascal Accepted 0.4 sec 61K

program p1221;

var
    c:array[1..100,1..100] of byte;
    i,j,k,m,n,best,a,b,d:integer;
    ok:boolean;


begin

{$IFNDEF ONLINE_JUDGE}
    assign(input,'input1221.txt');reset(input);
    assign(output,'output1221.txt');rewrite(output);
{$ENDIF}
    while true do begin
        readln(n);
        if n=0 then break;
        for i:=1 to n do begin
            for j:=1 to n-1 do read(c[i,j]);
            readln(c[i,n]);
        end;
        best:=0;
        for k:=n downto 3 do if odd(k) then begin
            for i:=1 to n-k+1 do if best=0 then
            for j:=1 to n-k+1 do if c[i,j]=1 then begin
                ok:=true;
                for a:=1 to k div 2 do begin
                    for b:=0 to ((k+1) div 2)-a-1 do
                    if c[i+a-1,j+b]=0 then ok:=false;
                    for b:=((k+1) div 2)-a to ((k-1) div 2)+a-1 do
                    if c[i+a-1,j+b]=1 then ok:=false;
                    for b:=((k-1) div 2)+a to k-1 do
                    if c[i+a-1,j+b]=0 then ok:=false;
                    if not ok then break;
                end;
                for a:=(k div 2)+1 to k do begin
                    for b:=0 to a-k-1+(k-1) div 2 do
                    if c[i+a-1,j+b]=0 then ok:=false;
                    for b:=a-k+(k-1) div 2 to k-a-1+(k+1) div 2 do
                    if c[i+a-1,j+b]=1 then ok:=false;
                    for b:=k-a+(k+1) div 2 to k-1 do
                    if c[i+a-1,j+b]=0 then ok:=false;
                    if not ok then break;
                end;
                if ok then begin best:=k; break end;
            end;
            if best<>0 then break;
        end;
        if best=0 then writeln('No solution') else writeln(best);
    end;
end.
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.032毫秒