Hex
TCO04 Semifinal 1 · 2004-09-07 · by dgoodman
Problem Statement
_
/h\_
\_/ \_
/v\_/ \_
\_/ \_/ \
/v\_/h\_/
\_/ \_/ \
/v\_/ \_/
\_/ \_/ \
\_/ \_/
\_/ \
\_/
Above is a picture of a 4 x 4 Hex game in progress. The board is a 4 x 4 collection of hexagons packed together, with 4 hexagons in each vertical column, and 4 hexagons in each diagonal from upper left to lower right. Two players play against each other. One of the players ('h') tries to make a horizontal chain of adjacent hexagons stretching between the left and right of the board. The other player ('v') tries to make a vertical chain of adjacent hexagons stretching from the bottom to the top of the board.
We can refer to any position on the board by a pair of coordinates giving the diagonal distance and vertical distance from the upper left hexagon. Using these coordinates, the two hexagons marked 'h' are located at (0,0) and at (2,1).
Given the size of the board and a list of all the marked hexagons, we want
software that can draw the board using characters as shown above.
Create a class Hex that contains a method picture that is given n (the vertical
and diagonal size of the board) and marks (a list of all the marked hexagons)
and that returns a picture of the board in the format shown above. The return
will be a
marks will be a
Constraints
- n will be between 2 and 10 inclusive.
- marks will contain between 0 and 50 elements inclusive.
- Each element of marks will contain exactly 3 characters.
- The first 2 characters in each element of marks will be digits less than n.
- The last character in each element of marks will be 'v' or 'h'.
- No 2 elements of marks will refer to the same hexagon.
4
{"00h","21h","01v","03v","02v"}
Returns: { " _", "/h\\_", "\\_/ \\_", "/v\\_/ \\_", "\\_/ \\_/ \\", "/v\\_/h\\_/", "\\_/ \\_/ \\", "/v\\_/ \\_/", "\\_/ \\_/ \\", " \\_/ \\_/", " \\_/ \\", " \\_/" }
Note that the elements in the returns are shown as string literals, so each backslash character in each String is shown as \\. So, for example, the second element of this return should contain just 4 characters (i.e. its length would be 4). This will print the following 4x4 picture: _ /h\_ \_/ \_ /v\_/ \_ \_/ \_/ \ /v\_/h\_/ \_/ \_/ \ /v\_/ \_/ \_/ \_/ \ \_/ \_/ \_/ \ \_/
3
{"00v","01v","02v","11h","21h"}
Returns: { " _", "/v\\_", "\\_/ \\_", "/v\\_/ \\", "\\_/h\\_/", "/v\\_/h\\", "\\_/ \\_/", " \\_/ \\", " \\_/" }
This will print the following 3x3 picture: _ /v\_ \_/ \_ /v\_/ \ \_/h\_/ /v\_/h\ \_/ \_/ \_/ \ \_/
9
{}
Returns: { " _", "/ \\_", "\\_/ \\_", "/ \\_/ \\_", "\\_/ \\_/ \\_", "/ \\_/ \\_/ \\_", "\\_/ \\_/ \\_/ \\_", "/ \\_/ \\_/ \\_/ \\_", "\\_/ \\_/ \\_/ \\_/ \\_", "/ \\_/ \\_/ \\_/ \\_/ \\", "\\_/ \\_/ \\_/ \\_/ \\_/", "/ \\_/ \\_/ \\_/ \\_/ \\", "\\_/ \\_/ \\_/ \\_/ \\_/", "/ \\_/ \\_/ \\_/ \\_/ \\", "\\_/ \\_/ \\_/ \\_/ \\_/", "/ \\_/ \\_/ \\_/ \\_/ \\", "\\_/ \\_/ \\_/ \\_/ \\_/", "/ \\_/ \\_/ \\_/ \\_/ \\", "\\_/ \\_/ \\_/ \\_/ \\_/", " \\_/ \\_/ \\_/ \\_/ \\", " \\_/ \\_/ \\_/ \\_/", " \\_/ \\_/ \\_/ \\", " \\_/ \\_/ \\_/", " \\_/ \\_/ \\", " \\_/ \\_/", " \\_/ \\", " \\_/" }
2
{"00h","11v"}
Returns: { " _", "/h\\_", "\\_/ \\", "/ \\_/", "\\_/v\\", " \\_/" }
5
{"42h","22h","12h","34v","43h"}
Returns: { " _", "/ \\_", "\\_/ \\_", "/ \\_/ \\_", "\\_/ \\_/ \\_", "/ \\_/ \\_/ \\", "\\_/h\\_/ \\_/", "/ \\_/h\\_/ \\", "\\_/ \\_/ \\_/", "/ \\_/ \\_/h\\", "\\_/ \\_/ \\_/", " \\_/ \\_/h\\", " \\_/v\\_/", " \\_/ \\", " \\_/" }
Submissions are judged against all 45 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Hex with a public method vector<string> picture(int n, vector<string> marks) · 45 test cases · 2 s / 256 MB per case