比赛 |
20120704 |
评测结果 |
AWAWWWWWWW |
题目名称 |
椰子 |
最终得分 |
20 |
用户昵称 |
wo shi 刘畅 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2012-07-04 10:17:22 |
显示代码纯文本
var
x,y,time,i,j,t,n:longint;
w,gx,gy:array[0..100000]of longint;
g:array[-1001..1001,-1001..1001]of longint;
begin
assign(input,'coconuts.in'); reset(input);
assign(output,'coconuts.out'); rewrite(output);
readln(t);
for time:=1 to t do
begin
readln(n);
for i:=1 to n do
for j:=1 to n do
g[i,j]:=0;
for j:=0 to n+1 do g[0,j]:=maxlongint;
for i:=1 to n do
begin
readln(y,w[i]);
for x:=n downto 0 do
if g[x,y]>0 then
begin
if (g[x,y-1]>0)and(g[x,y+1]>0) then
begin
g[x+1,y]:=i;
gx[i]:=x+1;
gy[i]:=y;
break;
end;
if (g[x,y-1]=0)and(g[x,y+1]=0) then
begin
if w[i]>w[g[x,y]] then
begin
g[x,y+1]:=g[x,y];
gx[g[x,y+1]]:=x;
gy[g[x,y+1]]:=y+1;
g[x,y]:=i;
gx[g[x,y]]:=x;
gy[g[x,y]]:=y;
break;
end
else begin
g[x,y-1]:=i;
gx[i]:=x;
gy[i]:=y-1;
break;
end;
end;
if (g[x,y-1]>0)and(g[x,y+1]=0) then
begin
if w[i]>w[g[x,y]] then
begin
g[x,y+1]:=g[x,y];
gx[g[x,y+1]]:=x;
gy[g[x,y+1]]:=y+1;
g[x,y]:=i;
gx[g[x,y]]:=x;
gy[g[x,y]]:=y;
break;
end
else begin
g[x,y+1]:=i;
gx[i]:=x;
gy[i]:=y+1;
break;
end;
end;
if (g[x,y-1]=0)and(g[x,y+1]>0) then
begin
if w[i]<w[g[x,y]] then
begin
g[x,y-1]:=i;
gx[i]:=x;
gy[i]:=y-1;
break;
end
else begin
g[x,y-1]:=g[x,y];
gx[g[x,y-1]]:=x;
gy[g[x,y-1]]:=y-1;
g[x,y]:=i;
gx[g[x,y]]:=x;
gy[g[x,y]]:=y;
break;
end;
end;
end;
end;
for i:=1 to n do writeln(gx[i],' ',gy[i]);
if time<t then writeln;
end;
close(input);
close(output);
end.