아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Map Puzzle

시간 제한1초메모리 제한512 MB

요약
인접한 변의 표시가 같도록 타일을 회전시켜 배치하고, 첫 타일은 왼쪽 위에 고정한 뒤 완성된 격자를 출력한다.
난이도

보통10점 중 7점

유형
백트래킹, 구현
정답자
아직 제출이 없습니다

문제

You must write a solver for a puzzle that depicts a map. Each tile is square with edges corresponding to markings on a map. There are six different possible edge types: Road (R), City (C), Farm (F), Stream (S), Lake (L), and Boulders (B). Tiles will fit in a grid of rows and columns where adjacent edges must match. Tile edges on the outer edge of the grid are not adjacent to any other tile edge, i.e. no wrap around.

입력

The first line of input will contain the number of test cases, T (1 ≤ T ≤ 50).

The first line of each test case will contain the number of rows and columns R C in a grid, (1 ≤ R, C ≤ 50).

The next R * C lines will each contain a puzzle tile, represented as 4 characters indicating the North, East, South, and West sides.

The first tile read in for each puzzle is the starter tile. It is fixed, i.e. it cannot be rotated, and will be placed in the first row and first column of the grid. Subsequent tiles can be placed in any other location in the puzzle grid and can be rotated as necessary to find a proper fit.

출력

Output consists of the completed puzzle, R * 5 lines each with C * 5 characters. Each 5x5 square represents a tile and looks like the following:

+---+
| F |
|L R|
| B |
+---+

Each puzzle is guaranteed to have a single solution.

Test cases will be separated by a single blank line.

예제1

  1. 예제 1

    입력
    2
    2 3
    FRCR
    CLLB
    FFSB
    FLRB
    LRLC
    FRSF
    2 2
    CCBC
    CSRB
    SLFF
    LCRR
    
    예상 출력
    +---++---++---+
    | F || B || R |
    |R R||R F||F S|
    | C || L || F |
    +---++---++---+
    +---++---++---+
    | C || L || F |
    |L L||L B||B F|
    | R || C || S |
    +---++---++---+
    
    +---++---+
    | C || R |
    |C C||C R|
    | B || L |
    +---++---+
    +---++---+
    | B || L |
    |B S||S F|
    | R || F |
    +---++---+