LSTTCD2 - Thử thách cực đại - Đá chìm đá nổi 2
Tác giả: flashmt
Ngôn ngữ: Pascal
const fi='';
fo='';
maxn=10010;
var n,num,pos,x,y:longint;
swap:boolean;
d,re:array[0..10001] of integer;
procedure rf;
begin
assign(input,fi);
reset(input);
read(n,x,y);
close(input);
end;
procedure gox1;
begin
while pos>1 do
begin
inc(num);
if pos=2 then d[1]:=num
else d[pos-2]:=num;
pos:=pos-2;
end;
if d[1]=0 then
begin
inc(num); d[1]:=num;
end;
end;
procedure go1y;
begin
if x>1 then
begin
inc(num); pos:=2;
if d[2]=0 then d[2]:=num
else
begin
d[3]:=num; inc(pos);
end;
end;
if d[y]>0 then exit;
while pos<y-1 do
begin
inc(pos);
if d[pos]=0 then
begin
inc(num); d[pos]:=num;
end;
end;
if y<n then
begin
inc(num); pos:=y+1; d[pos]:=num;
end
else
begin
inc(num); d[y]:=num;
end;
end;
procedure goyn;
begin
while pos<n do
begin
inc(num);
if pos=n-1 then d[n]:=num
else d[pos+2]:=num;
pos:=pos+2;
end;
end;
procedure gony;
begin
for pos:=n downto y do
if d[pos]=0 then
begin
inc(num);
d[pos]:=num;
end;
end;
function check:boolean;
begin
check:=(abs(x-y)=1) and (x>1) and (y<n);
end;
procedure pr;
begin
fillchar(d,sizeof(d),0);
fillchar(re,sizeof(re),0);
swap:=false;
if x>y then
begin
swap:=true; x:=n-x+1; y:=n-y+1;
end;
pos:=x; d[x]:=1; num:=1;
if d[y]>0 then exit;
gox1;
go1y;
if d[y]>0 then exit;
goyn;
gony;
end;
procedure wf;
var i:longint;
begin
assign(output,fo);
rewrite(output);
if (d[y]<n) or check then write(-1)
else
begin
for i:=1 to n do
re[d[i]]:=i;
if not swap then
for i:=2 to n do
if re[i]>re[i-1] then writeln('R ',re[i]-re[i-1])
else writeln('L ',re[i-1]-re[i])
else
for i:=2 to n do
if re[i]>re[i-1] then writeln('L ',re[i]-re[i-1])
else writeln('R ',re[i-1]-re[i]);
write('WIN');
end;
close(output);
end;
begin
rf;
pr;
wf;
end.