比赛 NOIP2008集训模拟3 评测结果 EEEEEEEEEE
题目名称 IP网络管理员 最终得分 0
用户昵称 NOIer 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-12 11:15:50
显示代码纯文本
Program Network;
Const
        MaxM    = 1000;
        Inf     = 'network.in';
        Ouf     = 'network.out';
Type
        node    = array[1..32] of integer;
Var
        data    : array[1..MaxM] of node;
        num     : array[1..MaxM] of Qword;
        i,j,n,m : longint;
        minposi : longint;
        min,max : Qword;

Function Change(x:node):Qword;
var     temp    : Qword;
        p       : integer;
begin
        temp:=0;
        for p:=1 to 32 do temp:=temp*2+x[p];
        Change:=temp;
end;

Procedure Deal(s:string; Var x:node; Var number:Qword);
var     a ,code ,l ,p : integer;
begin
        for p:=1 to 4 do begin
            val(copy(s,1,pos('.',s)-1),a,code);
            delete(s,1,pos('.',s));
            for l:=8*p downto 8*p-7 do begin
                x[l]:=a mod 2;
                a:=a shr 1;
            end;
        end;
        number:=Change(x);
end;

Procedure Init;
var     s : string;
begin
        min:=maxlongint;
        min:=min+min+1;
        max:=0;
        assign(input,inf); reset(input);
           readln(m);
           for i:=1 to m do begin
               readln(s);
               Deal(s+'.',data[i],num[i]);
               if num[i]>max then max:=num[i];
               if num[i]<min then begin
                  min:=num[i];
                  minposi:=i;
               end;
           end;
        close(input);
end;

Procedure Main;
var     temp,minn : Qword;
begin
        n:=0; temp:=1;
        while temp<(max-min+1) do begin
              inc(n);
              temp:=temp*2;
        end;
        for i:=32 downto 32-n+1 do data[minposi][i]:=0;
        minn:=Change(data[minposi]);
        if (minn+temp-1)<max then begin
           inc(n);
           data[minposi][32-n+1]:=0;
        end;
end;

Procedure out(x:node);
var     p,q,t   : longint;
begin
        for p:=1 to 4 do begin
            t:=0;
            for q:=p*8-7 to p*8 do t:=t*2+x[q];
            if p=4 then writeln(t)
                   else write(t,'.');
        end;
end;

Procedure Print;
begin
        assign(output,ouf); rewrite(output);
           out(data[minposi]);
           for i:=1 to 32-n do data[minposi][i]:=1;
           out(data[minposi]);
        close(output);
end;

BEGIN
        Init;
        Main;
        Print;
END.