QOJ.ac

QOJ

Time Limit: 6 s Memory Limit: 1024 MB Total points: 45

#5903. 异星考古学

Statistics

很久以前,一个外星文明建造了一座巨大的纪念碑。纪念碑的地面看起来像这样:

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

其中 '#' 代表红色地砖,'.' 代表蓝色地砖。这种图案向外延伸了数英里(为了解决本题,你可以假设它是无限大的)。如今,只剩下少数几块地砖。其余的已被甲烷雨和沙尘暴损坏。给定剩余地砖的位置和颜色,你能找到该图案的中心吗?

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。每个测试用例的第一行包含一个整数 $N$,表示剩余地砖的数量。接下来的 $N$ 行,每行包含 $X_i$、$Y_i$ 以及地砖的颜色('#' 或 '.')。

输出格式

对于每个测试用例,输出一行 "Case #c: $X$ $Y$",其中 $c$ 是测试用例编号(从 1 开始),$(X, Y)$ 是图案的中心位置。如果有多个可能的答案,输出曼哈顿距离($x$ 距离加上 $y$ 距离)到 $(0, 0)$ 最近的那个 $(X, Y)$。如果仍有平局,输出 $X$ 最大的那个。如果之后仍有平局,输出 $Y$ 最大的那个。如果没有可能的答案,输出 "Case #c: Too damaged"。

数据范围

$1 \le T \le 50$。

每个测试用例中的坐标列表不包含重复项。

子任务 1

$1 \le N \le 100$。 $-100 \le X_i \le 100$。 $-100 \le Y_i \le 100$。

子任务 2

$1 \le N \le 1000$。 $-10^{15} \le X_i \le 10^{15}$。 $-10^{15} \le Y_i \le 10^{15}$。

样例

样例输入 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

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.