QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 512 MB Puntuación total: 100 Hackeable ✓

#16791. 十字绣

Estadísticas

十字绣是一种自史前时代就已存在的针线活形式。一个十字绣图案由织物正面的若干个十字组成,这些十字在背面相连。传统上,整个图案应该用一根线绣成。

Carol 准备批量生产十字绣图案。每个图案都将配有一块矩形的织物和绣制该图案所需的线。Carol 希望最小化该图案所需的线段总长度。

给你图案的正面。你需要设计背面的走线,使得线的总长度最小。图案正面的十字是 8-连通的,即可以通过一系列国际象棋中王(king)的移动从任意一个十字到达其他任意一个十字。

输入格式

第一行包含两个整数 $w$ 和 $h$ —— 织物的宽度和高度($1 \le w, h \le 100$)。

接下来的 $h$ 行包含图案的正面。每行包含 $w$ 个字符,其中 'X' 表示一个十字,'.' 表示空白区域。图案正面至少包含一个十字,且所有十字是 8-连通的。

输出格式

输出的第一行应包含一个整数 $n$ —— 绣制该图案所需的针脚数。

接下来的 $n + 1$ 行应包含针眼从背面穿到正面或从正面穿到背面的点的坐标:对于 $i = 0..n$ 为 $x_i, y_i$。织物的左上角坐标为 $(0, 0)$,右下角坐标为 $(w, h)$。第一针走向图案正面,第二针走向背面,第三针走向正面,依此类推。允许在背面重复走线,但不能在正面重复。任何针脚的长度都不能为零。

样例

输入样例 1

3 2
.XX
..X

输出样例 1

11
1 1
2 0
2 1
3 0
2 0
3 1
2 1
3 2
2 2
3 1
2 1
1 0

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.