#P7. [Sleeping Cup #2] Sleeping Bear's Honey 2
[Sleeping Cup #2] Sleeping Bear's Honey 2
Person in Charge
Attention
This problem requires file I/O (honey2.in
/ honey2.out
).
Problem Background
Sleeping Bear is an adorable little bear who becomes even cuter the more honey it eats. However, every time it collects honey, bees sting its head all over. Today it wants to eat honey again but hopes to avoid getting stung, so it asks you to help design an escape route to evade the bees' pursuit.
Problem Description
Given a positive integer , representing a map with characters:
B
: Sleeping Bear's position (bees are right behind it by default);X
: Impassable terrain;R
: Passable road;L
: Lake location (only by jumping into the lake can Sleeping Bear avoid bee stings).
Known conditions:
B
positions should be treated asR
positions.- Sleeping Bear may start from any
R
position. - Sleeping Bear can face any initial direction (up, down, left, right) when escaping.
- Each move, Sleeping Bear can either:
- Move forward one cell in its current facing direction.
- Turn left ( counter-clockwise) then move forward one cell.
- Note: Sleeping Bear cannot turn around or turn right.
- A
R
position is considered safe if Sleeping Bear can reach anyL
position from it.
Determine which positions are safe.
Input Format
Multiple test cases.
First line: integer - number of test cases.
For each test case:
- First line: integer - map size;
- Next lines: characters each representing the map.
Output Format
For each test case, output lines of characters:
- Replace safe
R
positions withL
; - Replace unsafe
R
positions withX
; - Treat
B
positions asR
positions; - Keep original
L
andX
characters unchanged.
Sample
1
5
XXRRR
XRRRR
XXXXL
XXBRR
XXRRR
XXXXL
XXXXL
XXXXL
XXLLL
XXLLL
2
5
XXRRR
XRRRX
XXXXL
XXBRX
XXRRR
4
RRRR
XLXX
BXLR
RRLX
XXXXX
XXXXX
XXXXL
XXXXX
XXXXX
XLLL
XLXX
LXLL
LLLX
Sample 1 Explanation
For example, the B
position is safe because escape routes exist.
When facing right, the G
marks its only escape path:
XXRRR
XRRRR
XXXXL
XXBGG
XXRRR
When facing left, one possible escape route (marked by G
):
XXRRR
XRRRR
XXXXL
XXBRG
XXGGG
Actually, it could also make multiple loops in the bottom-right cells.
When facing down, both above routes are possible.
When facing up, escape becomes impossible.
Data Range
- For of cases: ,
- For of cases: ,
- Map contains only
B
,X
,R
,L
, with exactly oneB
. - No guarantees about the number of
L
s!
Official Solution
相关
在下列比赛中: