TupleLine
TCCC '03 NE/SE Regional · 2003-02-18 · by dgoodman
Problem Statement
Higher dimensions get a little harder to describe geometrically, but not algebraically! Every cell in an n-dimensional grid can be uniquely represented by an n-tuple specifying the "row" "column" "layer" "plane" "hyper-row" etc. (English fails us at about the same point as geometry fails us). We can define a straight line in an n-dimensional grid algebraically. It is a set of distinct cells that can be placed in a sequence such that the difference between each pair of adjacent cells is the same throughout the sequence. Of course, the difference between two n-tuples is an n-tuple. A maximal line in an n-dimensional grid of size k is a line containing k cells.
In a 3-dimensional grid of size 4, one example of a maximal straight line is (3,0,1),(2,1,1),(1,2,1),(0,3,1) which is a straight line of length 4. The difference between each pair of adjacent cells in the sequence is (-1,1,0).
You want to create a maximal line in your n-dimensional grid by adding to a
collection of cells that have already been chosen. Create a class TupleLine
that contains the method quickLine that takes an int size and a
Each
Constraints
- size is between 3 and 9 inclusive
- chosen contains between 1 and 50 elements inclusive
- each character in each element of chosen is a digit whose value is less than size
- each element in chosen contains the same number of characters, n. n is the dimension of the grid and is between 2 and 9 inclusive
4
{"00","02","21"}
Returns: 2
X - X - X X X X - - - - - - - - - X - - - X - - - - - - - - - - The left-hand picture shows the original situation. The right-hand picture shows the only way of completing a maximal line by adding two X's.
4
{"00","32","21","32"}
Returns: 3
X - - - - - - - - X - - - - X - There are lots of ways to form a maximal line with 3 more cells. Note that the cell "32" appears twice in chosen but, of course, this does not help us to form a maximal line.
3
{"0022","0202","0112","0000","0112"}
Returns: 0
These first three cells already form a maximal line in this 4-dimensional grid.
3
{"10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10","10"}
Returns: 2
9
{"010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000000","010000003","010000000","010000000","010000000","010000000"}
Returns: 7
Submissions are judged against all 61 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TupleLine with a public method int quickLine(int size, vector<string> chosen) · 61 test cases · 2 s / 256 MB per case