比赛 20120704 评测结果 AAAAAAAAAA
题目名称 椰子 最终得分 100
用户昵称 fuhao 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2012-07-04 09:51:09
显示代码纯文本
const maxn=1001;
var
 stop:boolean; min,max,n,i,t,p,w:longint;
 x,b:array[-maxn..2*maxn,0..maxn] of longint;
 y:array[0..maxn,1..2] of longint;
 procedure insert(p,w,j:longint);
 begin
  inc(x[p,0]); x[p,x[p,0]]:=w;
  inc(b[p,0]); b[p,b[p,0]]:=j;
  if p>max then max:=p;
  if p<min then min:=p;
 end;
 procedure moni;
 var i,j,t:longint;
 begin
  min:=maxlongint; max:=0;
  for i:=-maxn to 2*maxn do begin x[i,0]:=0; b[i,0]:=0; end;
  readln(n);
  for i:=1 to n do
   begin
    read(p,w); j:=i;
    repeat
     stop:=true;
     if x[p,0]=0 then insert(p,w,j) else
     if (x[p,0]<=x[p+1,0]) and (x[p,0]<=x[p-1,0])
      then insert(p,w,j) else
     if (x[p,0]>x[p+1,0]) and (x[p,0]>x[p-1,0])
      then begin
       stop:=false;
       if x[p,x[p,0]]<w then
        begin
         t:=x[p,x[p,0]]; x[p,x[p,0]]:=w; w:=t;
         t:=b[p,b[p,0]]; b[p,b[p,0]]:=j; j:=t;
         p:=p+1; end
       else p:=p-1;
       end else
     if (x[p,0]<=x[p+1,0]) and (x[p,0]>x[p-1,0]) then
      begin
       stop:=false;
       if x[p,x[p,0]]<w then
        begin
         t:=x[p,x[p,0]]; x[p,x[p,0]]:=w; w:=t;
         t:=b[p,b[p,0]]; b[p,b[p,0]]:=j; j:=t;
         p:=p-1 ;end
       else p:=p-1;
      end else
     if (x[p,0]<=x[p-1,0]) and (x[p,0]>x[p+1,0]) then
      begin
       stop:=false;
       if x[p,x[p,0]]<w then
       begin
        t:=x[p,x[p,0]]; x[p,x[p,0]]:=w; w:=t;
        t:=b[p,b[p,0]]; b[p,b[p,0]]:=j; j:=t;
        p:=p+1; end
       else p:=p+1;
      end;
    until stop;
  end;
 end;
 procedure print(k:longint);
 var i,j:longint;
 begin
  for i:=min to max do
   if b[i,0]<>0 then
    for j:=1 to b[i,0] do
     begin y[b[i,j],1]:=i; y[b[i,j],2]:=j; end;
  for i:=1 to n do writeln(y[i,2],' ',y[i,1]);
  if k<>t then writeln;
 end;
begin
 assign(input,'coconuts.in'); reset(input);
 assign(output,'coconuts.out'); rewrite(output);
 read(t);
 for i:=1 to t do
  begin
   moni;
   print(i);
  end;
 close(input); close(output);
end.