比赛 NOIP2008集训模拟3 评测结果 WWWWWWWWWW
题目名称 IP网络管理员 最终得分 0
用户昵称 rottenwood 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-12 09:45:32
显示代码纯文本
program networkip;
type
shuzu=array[1..1000,1..4] of longint;
shuzu1=array[1..2,1..4]of longint;
shuzu2=array[1..10] of longint;
var
f:shuzu;
s:shuzu1;
z:shuzu2;
i,j,k,n,m,x,y,x1,y1,temp,temp1,num,min,code:longint;
s1,s2:string;
procedure zhuanhuan(x:string);
  var
  i,j,k,ans:longint;
  a:array[1..8] of integer;
  begin
  for i:=1 to 8 do
   a[i]:=ord(x[i])-48;
   m:=a[8];
   ans:=1;
   for i:=7 downto 1 do begin
   ans:=ans*2;
   m:=m+ans*a[i];
   end;
   end;
begin
assign(input,'networkip.in');reset(input);
assign(output,'networkip.out');rewrite(output);
readln(n);
if n=0 then begin
writeln('0.0.0.0');
writeln('0.0.0.0');
close(output);
halt;
end;
z[1]:=2; z[2]:=4;z[3]:=8;z[4]:=16;z[5]:=32;
z[6]:=64;z[7]:=128;z[8]:=256;z[9]:=512;z[10]:=1024;
for i:=1 to n do
begin
readln(s1);
j:=1;
for k:=1 to 3 do
begin
s2:=copy(s1,1,pos('.',s1)-1);
delete(s1,1,pos('.',s1));
val(s2,f[i,j],code);
inc(j);
end;
val(s1,f[i,4],code);
end;
 for i:=1 to n-1 do
    for j:=i+1 to n do
      if (f[i,3]>f[j,3])
          or(f[i,3]=f[j,3])and(f[i,4]>f[j,4])
       then begin
             x:=f[i,1]; y:=f[i,2];  x1:=f[i,3]; y1:=f[i,4];
             f[i,1]:=f[j,1]; f[i,2]:=f[j,2]; f[i,3]:=f[j,3];f[i,4]:=f[j,4];
             f[j,1]:=x; f[j,2]:=y; f[j,3]:=x1; f[j,4]:=y1;
          end;
 temp:=f[1,4]-1;
 s[1,1]:=f[1,1];s[1,2]:=f[1,2]; s[1,3]:=f[1,3];s[1,4]:=temp;
 temp:=f[n,3]-f[1,3]; temp1:=f[n,4]-f[1,4];
 num:=temp*255+temp1+1;
 min:=maxlongint;
 for i:=1 to 10 do
 begin
  temp:=z[i]-num;
  if (temp<min)and(temp>0) then begin min:=temp; temp1:=i; end;
  end;
  s1:='';
  for i:=1 to 32-temp1 do
    s1:=s1+'1';
    for i:=1 to temp1 do
    s1:=s1+'0';
  for i:=1 to 4 do
  begin
    s2:=copy(s1,1,8);
    delete(s1,1,8);
    zhuanhuan(s2);
    s[2,i]:=m;
    end;
 for i:=1 to 3 do
 begin
 write(s[1,i]);
 write('.');
 end;
 writeln(s[1,4]);
 for i:=1 to 3 do
 begin
 write(s[2,i]);
 write('.');
 end;
 writeln(s[2,4]);
 close(output);
 end.