比赛 20120704 评测结果 AWWWWWWWWW
题目名称 椰子 最终得分 10
用户昵称 zhangchi 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2012-07-04 09:05:21
显示代码纯文本
var
	i,j,k,x,y,t,n:longint;
	map,num:array[0..1000,-1000..1000] of longint;
	place:array[1..1000,1..2] of longint;
	procedure down(var y,x,w,m:longint);
	var
		xp,yp:longint;
	begin
		if map[y-1,x]=0 then 
			begin 
				map[y,x]:=0; 
				dec(y); 
				map[y,x]:=w;
				num[y,x]:=m;
				place[m,1]:=y;
				place[m,2]:=x;				
				exit; 
			end;
		if map[y-1,x]<>0 then
			begin
				if (map[y-1,x-1]=0)and(map[y-1,x+1]=0) then
					begin
						if w>map[y-1,x] then
							begin
								map[y-1,x+1]:=map[y-1,x];
								num[y-1,x+1]:=num[y-1,x];
								place[num[y-1,x+1],1]:=y-1;
								place[num[y-1,x+1],2]:=x+1;
								yp:=y-1;
								xp:=x+1;
								while not((map[yp-1,xp-1]>0)and(map[yp-1,xp]>0)and(map[yp-1,xp+1]>0)) do
									down(yp,xp,map[yp,xp],num[yp,xp]);
								map[y,x]:=0;
								dec(y);
								map[y,x]:=w;
								num[y,x]:=m;
								place[m,1]:=y;
								place[m,2]:=x;				
								exit;
							end;
						if w<map[y-1,x] then
							begin
								map[y,x]:=0;
								x:=x-1;
								y:=y-1;
								map[y,x]:=w;
								num[y,x]:=m;
								place[m,1]:=y;
								place[m,2]:=x;				
								exit;
							end;				
					end;
				if (map[y-1,x-1]=0)and(map[y-1,x+1]<>0) then
					begin
						if w>map[y-1,x] then
							begin
								map[y-1,x-1]:=map[y-1,x];
								num[y-1,x-1]:=num[y-1,x];
								place[num[y-1,x-1],1]:=y-1;
								place[num[y-1,x-1],2]:=x-1;
								yp:=y-1;
								xp:=x-1;
								while not((map[yp-1,xp-1]>0)and(map[yp-1,xp]>0)and(map[yp-1,xp+1]>0)) do
									down(yp,xp,map[yp,xp],num[yp,xp]);
								map[y,x]:=0;
								dec(y);
								map[y,x]:=w;
								num[y,x]:=m;
								place[m,1]:=y;
								place[m,2]:=x;				
								exit;
							end;
						if w<map[y-1,x] then
							begin
								map[y,x]:=0;
								x:=x-1;
								y:=y-1;
								map[y,x]:=w;
								num[y,x]:=m;
								place[m,1]:=y;
								place[m,2]:=x;				
								exit;
							end;
					end;
				if (map[y-1,x-1]<>0)and(map[y-1,x+1]=0) then
					begin
						if w>map[y-1,x] then
							begin
								map[y-1,x+1]:=map[y-1,x];
								num[y-1,x+1]:=num[y-1,x];
								place[num[y-1,x+1],1]:=y-1;
								place[num[y-1,x+1],2]:=x+1;
								yp:=y-1;
								xp:=x+1;
								while not((map[yp-1,xp-1]>0)and(map[yp-1,xp]>0)and(map[yp-1,xp+1]>0)) do
									down(yp,xp,map[yp,xp],num[yp,xp]);
								map[y,x]:=0;
								dec(y);
								map[y,x]:=w;
								num[y,x]:=m;
								place[m,1]:=y;
								place[m,2]:=x;				
								exit;
							end;
						if w<map[y-1,x] then
							begin
								map[y,x]:=0;
								x:=x+1;
								y:=y-1;
								map[y,x]:=w;
								num[y,x]:=m;
								place[m,1]:=y;
								place[m,2]:=x;				
								exit;
							end;
					end;		
			end;	
	end;
	procedure work(p,w:longint);
	var
		i:longint;
	begin
		for i:=1 to 1000 do
			if map[i,p]=0 then break;
		place[j,1]:=i;
		place[j,2]:=p; 
		map[i,p]:=w; 
		num[i,p]:=j;
		while not((map[i-1,p-1]>0)and(map[i-1,p]>0)and(map[i-1,p+1]>0)) do down(i,p,w,j);	
	end;
begin
	assign(input,'coconuts.in'); reset(input);
	assign(output,'coconuts.out'); rewrite(output);
	for i:=-1000 to 1000 do
		map[0,i]:=999999;
	readln(t);
	for i:=1 to t do
		begin
			readln(n);
			for j:=1 to n do
				begin
					readln(x,y);
					work(x,y);
				end;	
			for j:=1 to n do
				begin
					writeln(place[j,1],' ',place[j,2]);
					map[place[j,1],place[j,2]]:=0;
				end;
			if i<>t then writeln;
		end;
	close(input); close(output);
end.