Cod sursa(job #115593)

Utilizator ProtomanAndrei Purice Protoman Data 16 decembrie 2007 18:17:17
Problema Grozavesti Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.34 kb
type grozav=record
            x,ii,jj:longint;
     end;

var f1,f2:text;
    i,j,n,nr,min,poz:longint;
    sol,drs:array[0..1000] of grozav;
    a:array[0..310,0..310] of longint;
    v:array[0..1000] of longint;
    aux:grozav;
begin
        assign(f1,'grozavesti.in');
        reset(f1);
        assign(f2,'grozavesti.out');
        rewrite(f2);
        read(f1,n);
        for i:=1 to n do
        begin
                sol[i].x:=maxlongint;
                for j:=1 to n do
                begin
                        read(f1,a[i,j]);
                        if (sol[i].x>a[i,j])and(v[j]=0) then
                        begin
                                v[sol[i].jj]:=0;
                                sol[i].ii:=i;
                                sol[i].jj:=j;
                                sol[i].x:=a[i,j];
                                v[sol[i].jj]:=1;
                        end;
                end;
        end;
        drs:=sol;
        for i:=1 to n-1 do
        begin
                min:=maxlongint;
                for j:=i+1 to n do
                        if sol[j].x<min then
                        begin
                                min:=sol[j].x;
                                poz:=j;
                        end;
                if min<sol[i].x then
                begin
                        aux:=sol[poz];
                        sol[poz]:=sol[i];
                        sol[i]:=aux;
                        inc(nr);
                end;
                if i<>sol[i].jj then
                        inc(nr);
        end;
        writeln(f2,nr);
        sol:=drs;
        for i:=1 to n-1 do
        begin
                min:=maxlongint;
                for j:=i+1 to n do
                        if sol[j].x<min then
                        begin
                                min:=sol[j].x;
                                poz:=j;
                        end;
                if min<sol[i].x then
                begin
                        aux:=sol[poz];
                        sol[poz]:=sol[i];
                        sol[i]:=aux;
                        writeln(f2,'L ',sol[i].ii,' ',i);
                end;
                if i<>sol[i].jj then
                        writeln(f2,'C ',sol[i].jj,' ',i);
        end;
        close(f1);
        close(f2);
end.