QOJ.ac

QOJ

Time Limit: 6 s Memory Limit: 256 MB Total points: 100

#21184. 瓷器店里的公牛

Statistics

Farmer John 决定给家里添些装饰。他去当地瓷器店,看中了一尊精致的玻璃奶牛像,决定买下,因为它正适合放在壁炉上方的壁炉架上。

奶牛像的形状用 $N \times M$ 字符网格表示($3 \leq N, M \leq 500$),如下所示。小写字母是雕像的一部分,表示不同颜色;. 则不是。

...............
...............
x..x...........
xxxx...........
xxxxaaaaaaa...
.xx.aaaaaaaaa..
....aaaaaaa.aa.
....ll...ll....
....vv...vv....
...............

不幸的是,购买前一刻,一头公牛冲过商店,打碎了奶牛像和架上许多其他玻璃物品!奶牛像碎成 3 块,很快混入地上的总共 $K$ 块碎片中($4 \leq K \leq 100$)。这 $K$ 块碎片每块都像原雕像一样,用字符网格表示。

请帮 FJ 求出从地上 $K$ 块中选出 3 块,能粘合修复原雕像的组合有多少种。

地上的碎片可能被上下或左右翻转,或旋转了 90 度的倍数。给定原图和 $K$ 块碎片的网格,寻找能拼回原图的 3 块碎片组合,允许平移、翻转或旋转 90 度的倍数。叠放后,3 块碎片必须恰好组成原图,且原图中每个有色方格恰好由一块碎片提供。

输入格式

第一行包含整数 $K$。随后是 $K + 1$ 个图形描述,第一个为原玻璃奶牛像,其后 $K$ 个为碎片。

每个描述先给出一行整数 $R$ 和 $C$($1 \le R, C \le 100$)。随后 $R$ 行,每行包含 $C$ 个小写字母字符,描述各格的颜色。每块碎片在水平、竖直相邻意义下连通,并至少有一个非空格。

输出格式

输出满足碎片 $i$、$j$、$k$ 能拼成原玻璃奶牛像的三元组 $i, j, k$($i < j < k$)的数量。

样例

输入格式 1

5
5 5
aaaaa
..a..
bbabb
..a..
aaaaa
3 5
..abb
..a..
aaaaa
5 2
a.
a.
aa
a.
a.
1 2
bb
1 5
bbabb
2 5
aaaaa
..a..

输出格式 1

3

说明

三个解分别使用碎片 $(0, 1, 2)$、$(0, 2, 4)$、$(1, 3, 4)$。

本题每个测试用例的时间限制为 6 秒,Java 和 Python 提交的时间限制为其两倍。

题目作者:Brian Dean

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.