Thứ Năm, 19 tháng 5, 2022

pv pascal


var a:array[0..1000,0..1000] of longint;
        res:array[0..1000000] of longint;
        x,m,n,i,j,d:longint;

procedure nhap;
var i,j:longint;
begin
readln(m,n);
for i:=1 to m do
                for j:=1 to n do read(a[i,j]);
end;
function dt(x,y:longint):longint;
var i,j:longint;
begin
        i:=1;
        while a[x+i,y]=1 do inc(i);
        j:=1;
        while a[x,y+j]=1 do inc(j);
        exit(i*j);
end;

procedure tinh_cac_hinh;
var i,j:longint;
begin
        d:=0;
        for i:=1 to m do
                for j:=1 to n do
                        if (a[i,j]=1) and (a[i-1,j]=0) and (a[i,j-1]=0) then
                        begin
                                x:=dt(i,j);
                                inc(d);
                                res[d]:=x;
                        end;
end;

procedure sort;
var i,j,t:longint;
begin
        for i:=1 to d-1 do
                for j:=1 to d-i do
                        if res[j]>res[j+1] then
                        begin
                                t:=res[j];
                                res[j]:=res[j+1];
                                res[j+1]:=t;
                        end;
    for i:=1 to d do writeln(res[i]);
end;

begin
        assign(input,'pv.inp');reset(input);
        assign(output,'pv.out');rewrite(output);
        nhap;

    tinh_cach_hinh;
        sort;        
end.

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.