假设我们有一边长为S的正方形,以及N块长为X,宽为Y的矩形瓷砖。程序必须展示所有这些瓷砖可以如何排列在一个网格中,以便没有两个瓷砖相互接触。
通过展示,我指的是程序必须展示每个瓷砖左上角的坐标集合。
我尝试按照以下方式进行:
你能建议一些东西吗?或者也许有一个更高效的算法吗?
注意:我试图在Prolog中实现它。
通过展示,我指的是程序必须展示每个瓷砖左上角的坐标集合。
我尝试按照以下方式进行:
Find a base case where I try to place every copy with 1 square separation. For example, for 6 copies of a 1x2 tile on a 6x6 grid, the base case is
xx_xx_ ______ xx_xx_ ______ xx_xx_ ______
Move the last tile to possible positions.
Return the last tile to the base case, move the tile before the last one to the possible position. Repeat Step 2.
Do it back for every tile.
xx____ This tile
___xx_ and this one has a difference in row numbers 1.
xx____
___xx_
xx____
___xx_
你能建议一些东西吗?或者也许有一个更高效的算法吗?
注意:我试图在Prolog中实现它。
(S+1)
正方形和 N 个尺寸为(X+1)x(Y+1)
的矩形时,"不接触" 条件转化为 "不重叠"。这应该更容易实现。 - coproc