记录编号 39087 评测结果 AAAAAAAAAA
题目名称 椰子 最终得分 100
用户昵称 Gravatarczp 是否通过 通过
代码语言 Pascal 运行时间 0.103 s
提交时间 2012-07-04 16:26:45 内存使用 5.58 MiB
显示代码纯文本
var
 a:array[-200..1200,0..1009] of longint;
 p,w,ansx,ansy:array[1..1000] of longint;
 i,n,h,v,vv,hx:longint;
procedure put(i,x,h:longint);
 begin
  if (a[x,h-1]=0) then put(i,x,h-1) else
   begin
    if (a[x-1,h-1]>0) and (a[x+1,h-1]>0) then
     begin
      a[x,h]:=i;
      ansx[i]:=x;
      ansy[i]:=h;
      if h>hx then hx:=h;
      exit;
     end;
    if (a[x+1,h-1]>0)  then
     begin
      if w[i]>w[a[x,h-1]] then
       begin
        put(a[x,h-1],x-1,h-1);
        a[x,h-1]:=i;
        ansx[i]:=x;
        ansy[i]:=h-1;
       end else begin
         put(i,x-1,h-1);
        end;
      exit;
     end;
    if (a[x-1,h-1]>0)  then
     begin
      if w[i]>w[a[x,h-1]] then
       begin
        put(a[x,h-1],x+1,h-1);
        a[x,h-1]:=i;
        ansx[i]:=x;
        ansy[i]:=h-1;
       end else begin
         put(i,x+1,h-1);
        end;
      exit;
     end;
     if w[i]>w[a[x,h-1]] then
       begin
        put(a[x,h-1],x+1,h-1);
        a[x,h-1]:=i;
        ansx[i]:=x;
        ansy[i]:=h-1;
       end else begin
         put(i,x-1,h-1);
       end;
   end;
 end;
begin
 assign(input,'coconuts.in');reset(input);
 assign(output,'coconuts.out');rewrite(output);
 readln(vv);
 for v:=1 to vv do
 begin
  fillchar(a,sizeof(a),0);
  for i:=-200 to 1200 do
    a[i,0]:=1001;
  hx:=0;
  readln(n);
  for i:=1 to n do
   begin
    readln(p[i],w[i]);
    put(i,p[i],hx+1);
   end;
  for i:=1 to n do
   writeln(ansy[i],' ',ansx[i]);
  writeln;
 end;
 close(input);close(output);
end.