Given colored tiles from an infinite square ring pattern, find the pattern center that fits all tiles with the stated tie breaks.
Medium6Brute forceMathGeometryNo attempts yetTime limit5sMemory limit512 MBAn alien civilization built a giant monument long ago. Its floor looked like this:
###############
#.............#
#.###########.#
#.#.........#.#
#.#.#######.#.#
#.#.#.....#.#.#
#.#.#.###.#.#.#
#.#.#.#.#.#.#.#
#.#.#.###.#.#.#
#.#.#.....#.#.#
#.#.#######.#.#
#.#.........#.#
#.###########.#
#.............#
###############
A # is a red tile and a . is a blue tile. The pattern went on for miles in every direction, so treat it as infinite. Methane rain and dust storms have destroyed almost all of it, and only a few tiles are left.
The pattern has one center (X,Y). The tile at (x,y) is red when max(∣x−X∣,∣y−Y∣) is odd, and blue when that value is even. In the picture above the center is the single blue tile in the middle.
Given the position and the color of every remaining tile, find the center of the pattern.
The first line contains the number of test cases T. Each test case starts with a line containing N, the number of remaining tiles. Each of the next N lines contains Xi, Yi, and the color of that tile, which is either # or ..
For each test case, print one line of the form Case #c: X Y, where c is the test case number starting from 1 and (X,Y) is the center of the pattern. If more than one center is possible, print the one closest to (0,0) in Manhattan distance, that is, the distance in x plus the distance in y. If several centers are still tied, print the one with the largest X. If there is still a tie, print the one with the largest Y. If no center is possible, print Case #c: Too damaged instead.