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.