比赛 |
20120704 |
评测结果 |
AAAAAAAAAA |
题目名称 |
椰子 |
最终得分 |
100 |
用户昵称 |
IMSL77 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2012-07-04 11:56:06 |
显示代码纯文本
program main;
type
integer=longint;
const
maxn=1100;
var
test:integer;
n:integer;
map:array[-2000..3000,1..1000] of integer;
weight:array[1..maxn] of integer;
coco:array[1..maxn,1..2] of integer;
top:array[-2000..3000] of integer;
procedure Fopen;
begin
assign(input,'coconuts.in');
reset(input);
assign(output,'coconuts.out');
rewrite(output);
end;
procedure Fclose;
begin
close(input);
close(output);
end;
procedure fall(x,k:integer);
var
w,v:integer;
begin
if top[x]=0 then
begin
top[x]:=1;
map[x,1]:=k;
coco[k,1]:=1; coco[k,2]:=x;
exit;
end;
w:=weight[k];
v:=weight[map[x,top[x]]];
if (map[x-1,top[x]]=0) and (map[x+1,top[x]]=0) then
begin
if w>v then
begin
fall(x+1,map[x,top[x]]);
map[x,top[x]]:=0;
dec(top[x]);
fall(x,k);
end else
fall(x-1,k);
exit;
end;
if (map[x-1,top[x]]>0) and (map[x+1,top[x]]>0) then
begin
inc(top[x]);
map[x,top[x]]:=k;
coco[k,1]:=top[x]; coco[k,2]:=x;
exit;
end;
if map[x-1,top[x]]=0 then
begin
if w>v then
begin
fall(x-1,map[x,top[x]]);
map[x,top[x]]:=0;
dec(top[x]);
fall(x,k);
end else
fall(x-1,k);
exit;
end;
if map[x+1,top[x]]=0 then
begin
if w>v then
begin
fall(x+1,map[x,top[x]]);
map[x,top[x]]:=0;
dec(top[x]);
fall(x,k);
end else
fall(x+1,k);
exit;
end;
end;
procedure Solve;
var
i:integer;
x,w:integer;
begin
readln(n);
fillchar(map,sizeof(map),0);
fillchar(top,sizeof(top),0);
for i:=1 to n do
begin
readln(x,w);
weight[i]:=w;
fall(x,i);
end;
for i:=1 to n do writeln(coco[i,1],' ',coco[i,2]);
if test>0 then writeln;
end;
begin
Fopen;
readln(test);
while test>0 do
begin
dec(test);
Solve;
end;
Fclose;
end.