Problem Description
Given an equilateral triangle of side length n broken into n² unit equilateral triangles (with row i containing 2i - 1 triangles indexed from (i,1) to (i,2i-1)), you are allowed to initially color k triangles red. Then, repeatedly, any white triangle that has at least two red neighbors (neighbors share a side) becomes red. Find the minimum set of initially red triangles (by their coordinates) such that after the algorithm finishes all triangles end up red.
Key Insights
- The triangle is structured with each row i having exactly 2i - 1 triangles.
- Neighbors are defined as triangles that share a side; note that interior triangles have many neighbors while boundary ones typically have fewer.
- A viable and optimal approach is to initially color the boundary triangles: specifically, the leftmost and rightmost triangles of each row.
- For the first row, both “leftmost” and “rightmost” coincide, so only one triangle is chosen.
- This strategy guarantees that every interior (white) triangle eventually gets at least two red neighbors from its adjacent boundary triangles, triggering the propagation algorithm.
Space and Time Complexity
Time Complexity: O(n), as we simply iterate through n rows to generate the coordinates. Space Complexity: O(n), since we store a list of roughly 2n - 1 coordinates.
Solution
The idea is to initially color the boundary triangles because they form the “seed” that triggers the red color propagation. For every row i:
- If i = 1, we add the only triangle (1,1).
- For i ≥ 2, we add the leftmost triangle (i,1) and the rightmost triangle (i, 2i-1).
This set of red triangles is minimal and ensures that every white triangle eventually gets at least two red neighbors due to the structure of the triangle connectivity.
Data structures used:
- A list (or array) of coordinate pairs to store the positions of the initially red triangles.
Algorithm:
- Loop over rows 1 through n.
- For row 1, add (1,1).
- For subsequent rows, add (i,1) and (i, 2i-1).
- Return the list of coordinate pairs.
This straightforward approach leverages the intrinsic structure of the triangle and avoids additional overhead.