logo AlgoBeat OnlineJudge
登录 注册

#213449. [GCJ 2012 Finals] Xeno-archaeology

内存限制:1024 MiB 时间限制:6000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Long ago, an alien civilization built a giant monument. The floor of the monument looked like this:

###############
#.............#
#.###########.#
#.#.........#.#
#.#.#######.#.#
#.#.#.....#.#.#
#.#.#.###.#.#.#
#.#.#.#.#.#.#.#
#.#.#.###.#.#.#
#.#.#.....#.#.#
#.#.#######.#.#
#.#.........#.#
#.###########.#
#.............#
###############

Each '#' represents a red tile, and each '.' represents a blue tile. The pattern went on for miles and miles (you may, for the purposes of the problem, assume it was infinite). Today, only a few of the tiles remain. The rest have been damaged by methane rain and dust storms. Given the locations and colours of the remaining tiles, can you find the center of the pattern?

输入格式

The first line of the input gives the number of test cases, . test cases follow. Each one starts with a line containing , the number of remaining tiles. The next lines each contain , , and the tile colour (either '#' or '.').

输出格式

For each test case, output one line containing "Case #: ", where is the case number (starting from 1) and (, ) is the location of the center of the pattern. If there is more than one possible answer, output the (, ) closest to (0, 0) in Manhattan distance (the distance in , plus the distance in ). If there are still ties, output the one with the largest . If there are still ties after that, output the one with the largest . If there is no possible answer, output "Case #: Too damaged".

样例

样例输入 1

6
1
0 0 .
1
0 0 #
3
0 0 #
0 1 #
1 0 #
5
50 30 #
49 30 #
49 31 #
49 32 #
50 32 #
2
-98 0 #
99 50 .
4
88 88 .
88 89 .
89 88 .
89 89 .

样例输出 1

Case #1: 0 0
Case #2: 1 0
Case #3: 1 1
Case #4: 50 31
Case #5: 1 0
Case #6: Too damaged

数据范围与提示

Limits

  • The list of coordinates in each test case will not contain duplicates.

Test set 1 (12 Pts, Visible Verdict)

Test set 2 (33 Pts, Hidden Verdict)