比赛 |
20120704 |
评测结果 |
AWAWWWWWWW |
题目名称 |
椰子 |
最终得分 |
20 |
用户昵称 |
SnowDancer |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2012-07-04 11:20:40 |
显示代码纯文本
var
x,y:array[1..1000] of longint;
w:array[1..1000] of longint;
co:array[0..60,-1000..1000] 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,yl]<>0) then exit;
yp:=co[xp,y[code]];
co[x[code],y[code]]:=0;
dec(co[0,y[code]],2);
if (co[xp,yl]=0)and(co[xp,yr]=0) then begin
if w[code]>w[yp] then begin
y[yp]:=yr;
move(yp);
move(code);
end else begin
y[code]:=yl;
move(code);
end;
exit;
end;
if co[xp,yl]<>0 then
if w[code]>w[yp] then begin
y[yp]:=yr;
move(yp);
move(code);
end else begin
y[code]:=yr;
move(code);
end
else
if w[code]>w[yp] then begin
y[yp]:=yl;
move(yp);
move(code);
end else begin
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.