是否可能有布尔矩阵的旋转不变标识符?
假设我有一个由 1 和 0 组成的矩阵,并且我希望该矩阵有一个“标识符”,无论该矩阵旋转 90 度、180 度还是 270 度,它都采用相同的值,即 4 到 1 映射。理想情况下,该标识符应为矩阵大小的 1/4。是否可以编写一个函数来执行此映射?
背景:我正在查看UVa问题集上的这个问题。我并不完全需要这样的函数来解决问题,但它的存在似乎是合理的,并且使用它会产生更优雅的解决方案。
Say I have a matrix of ones and zeros, and I would like a 'identifier' for this matrix that takes the same value regardless of whether the matrix is rotated by 90, 180, or 270 degrees, i.e. a 4-to-1 mapping. Ideally, this identifier should be 1/4 the size of the matrix. Is it possible to write a function that does this mapping?
Background: I was looking at this problem on the UVa problem set. I don't exactly need such a function to solve the problem, but it seems reasonable that it would exist, and using it would make for a more elegant solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。您可以获取原始矩阵 A,并将其旋转为所有可能的配置 A'、A'' 和 A'''。然后,您可以使用您选择的某种排序方式对它们进行排序(只需保持一致),选择第一个,然后使用您选择的任何散列函数对其进行散列(同样,实际的散列函数并不重要,只需保持一致)。
显然,这可以通过不实际执行完整的旋转和排序来进行大量优化 - 您可以惰性地进行比较,一旦知道哪个旋转首先排序就停止 - 但原理是相同的。
Yes. You can take your original matrix A, and rotate it to all the possible configurations A', A'' and A'''. You can then sort these using some sorting of your choosing (just be consistent) , pick the first, and hash that using any hash function of your choosing (again, the actual hash function doesn't matter, just be consistent).
Obviously this can be optimized heavily by not actually doing the full rotation and sorting - you can do the comparisons lazily, stopping as soon as you know which rotation sorts first - but the principle is the same.
您可以对所有旋转进行位异或,这将是一个对称标识符。
You can just bit XOR all the rotations, that will be a symmetric identifier.