RotatingTriangles
SRM 444 · 2009-07-08 · by vexorian
SRM 444 · 2009-07-08 · by vexorian · Dynamic Programming, String Manipulation
Problem Statement
Problem Statement
NOTE: This problem statement contains images that may not display properly if viewed outside of the applet.
You are given a white rectangular grid made up of square cells. Some cells contain black squares, and some contain black squares that have been folded in half to form right triangles. Each of these triangles can be rotated left or right by any multiple of 90 degrees. They can also be unfolded to become squares. However, black squares cannot be folded to become triangles.
Your task is to generate proper black triangles in the grid using the aforementioned operations. A black triangle is considered proper within a grid configuration if no other black shape shares a line segment with it. However, black shapes may still share one or more points with the triangle.
The grid will be given as aString[] , where the j-th character of the i-th element represents the cell at row i, column j. '.' represents an empty cell, '#' represents a cell containing a black square, and '/' represents a cell containing a black triangle. Return the total number of distinct proper black triangles that can be formed in this grid. Two triangles are considered distinct if they differ in at least one vertex.
For example, consider the following input grid:

It is possible to generate 5 distinct proper black triangles:

You are given a white rectangular grid made up of square cells. Some cells contain black squares, and some contain black squares that have been folded in half to form right triangles. Each of these triangles can be rotated left or right by any multiple of 90 degrees. They can also be unfolded to become squares. However, black squares cannot be folded to become triangles.
Your task is to generate proper black triangles in the grid using the aforementioned operations. A black triangle is considered proper within a grid configuration if no other black shape shares a line segment with it. However, black shapes may still share one or more points with the triangle.
The grid will be given as a
For example, consider the following input grid:

It is possible to generate 5 distinct proper black triangles:

Constraints
- grid will contain between 1 and 50 elements, inclusive.
- Each element of grid will contain between 1 and 50 characters, inclusive.
- Each element of grid will contain the same number of characters.
- Each character in grid will be '.', '#' or '/'.
Examples
0)
{"//"}
Returns: 10
1)
{"#//#./#/#",
"####.#/##",
"...../#.#",
".....####"}
Returns: 5
This is the example from the statement.
2)
{".#.",
"#/#",
".#."}
Returns: 0
3)
{".../...",
"..///./",
".//#/./"}
Returns: 46
4)
{"#//##/#//..##../.#/.../////#/##/",".////.//./.#/.//#//#####.//.###.","///##/..##..##.##.//./##.//#/.#/","#/#//././/#.#/#//.#./#..#.///#.#","#/#./#...##/.//##/.#/#/.#/./#..#",".//////##./#/##/##///.#.#///////","...//#./#.#/.///#.#././#//#/#.##","//#.#/###/../#.//../#/./#/##/..#","#/./#/#.././..///..##.///.##../#","#//...##/..#..#.##.///./.#/.//#.","/.##///##/##.#...#/...#/..#/.#..","##./##/#.../#.#...###..#/...#/..","#.#/./.#.#//#//./#/#./.##./#/#/.",".###/#/////...#.##//#.##./#.#.#.","#///###..#..#/..///.#.#../##....","#/..//.../#.##//./.#/#///#.#///#","///#..././##/#///#/#//#.../.#//#","#.//#/./##/##.###.#/#./#/##./##.","/./#..#.#..#..#....#/##.##///.#.","...#./##./#..##../#/#/#/##//.#.."}
Returns: 540
Submissions are judged against all 67 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class RotatingTriangles with a public method int count(vector<string> grid) · 67 test cases · 2 s / 256 MB per case

