Cod sursa(job #12849)

Utilizator ProtomanAndrei Purice Protoman Data 4 februarie 2007 22:56:21
Problema Dame Scor 75
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.77 kb
var n,m,i,x:longint; f1,f2:text;
begin
        assign(f1,'dame.in');
        reset(f1);
        assign(f2,'dame.out');
        rewrite(f2);
        read(f1,n);
        x:=(n+1) div 2;
        m:=n;
        if n=2 then begin
                writeln(f2,'1');
                write(f2,'1 1');
        end;
        if n=3 then begin
                writeln(f2,'2');
                writeln(f2,'1 2');
                writeln(f2,'3 1');
        end;
        if (n<>2) and (n<>3) then writeln(f2,n);
        if (n mod 12<>2)and(n mod 6<>3)and(n mod 12<>8) then
        begin
                for i:=1 to n do begin
                        if i mod 2=1 then begin writeln(f2,i,' ',x); dec(x); end;
                        if i mod 2=0 then begin writeln(f2,i,' ',m); dec(m); end;
                end;
        end;
        if n mod 12=8 then
        begin
                for i:=1 to n do begin
                        if i mod 2=1 then begin writeln(f2,i,' ',x); dec(x); end;
                        if i mod 2=0 then begin
                                if i mod 4=2 then writeln(f2,i,' ',m-1)
                                             else begin writeln(f2,i,' ',m); m:=m-2; end;
                        end;
                end;
        end;
        if (n mod 12=9) then
        begin
        m:=1;
                        for i:=1 to n do begin
                        if i mod 2=1 then begin writeln(f2,i,' ',m); inc(m); end;
                        if i mod 2=0 then begin
                                if i mod 4=2 then writeln(f2,i,' ',x+2)
                                             else begin writeln(f2,i,' ',x+1); x:=x+2; end;
                                end;
                        end;
        end;
        close(f1);
        close(f2);
end.