记录编号 |
39109 |
评测结果 |
AAAWWWWWWW |
题目名称 |
椰子 |
最终得分 |
30 |
用户昵称 |
wo shi 刘畅 |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
0.468 s |
提交时间 |
2012-07-04 17:50:31 |
内存使用 |
16.61 MiB |
显示代码纯文本
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:=-1001 to 1001 do
g[i,j]:=0;
for j:=-1001 to 1001 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.