记录编号 39101 评测结果 AAAAAAAAAA
题目名称 椰子 最终得分 100
用户昵称 GravatarSnowDancer 是否通过 通过
代码语言 Pascal 运行时间 0.172 s
提交时间 2012-07-04 17:20:57 内存使用 11.63 MiB
显示代码纯文本
var
  x,y:array[1..1000] of longint;
  w:array[1..1000] of longint;
  co:array[0..1000,-1000..2000] of longint;
  n,i,j,k,l,test:longint;
procedure move(code:longint);
  var
    xp,yl,yr,yp:longint;
  begin
    if x[code]>co[0,y[code]] then begin
      inc(co[0,y[code]]);
      x[code]:=co[0,y[code]];
      co[x[code],y[code]]:=code;
    end;
    xp:=x[code]-1; yl:=y[code]-1; yr:=y[code]+1;
    if (x[code]=1) or (co[xp,yl]<>0) and (co[xp,yr]<>0) then exit;
    yp:=co[xp,y[code]];
    co[x[code],y[code]]:=0;
    if (co[xp,yl]=0)and(co[xp,yr]=0) then begin
      if w[code]>w[yp] then begin
        dec(co[0,y[code]],2);
        y[yp]:=yr;
        move(yp);
        move(code);
      end else begin
        dec(co[0,y[code]]);
        y[code]:=yl;
        move(code);
      end;
      exit;
    end;
    if co[xp,yl]<>0 then
      if w[code]>w[yp] then begin
        dec(co[0,y[code]],2);
        y[yp]:=yr;
        move(yp);
        move(code);
      end else begin
        dec(co[0,y[code]]);
        y[code]:=yr;
        move(code);
      end
    else
      if w[code]>w[yp] then begin
        dec(co[0,y[code]],2);
        y[yp]:=yl;
        move(yp);
        move(code);
      end else begin
        dec(co[0,y[code]]);
        y[code]:=yl;
        move(code);
      end;
  end;
begin
assign(input,'coconuts.in'); reset(input);
assign(output,'coconuts.out'); rewrite(output);
  readln(test);
  while test>0 do begin
    readln(n);
    fillchar(co,sizeof(co),0);
    for i:=1 to n do begin
      readln(y[i],w[i]);
      x[i]:=maxlongint;
      move(i);
    end;
    for i:=1 to n do writeln(x[i],' ',y[i]);
    writeln;
    dec(test);
  end;
close(input); close(output);
end.