作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我有以下形状(字符串类型);
..ee
e..e
以及以下空间:
||..
.|..
我的方法shapeFitsAt()
确定给定的形状是否可以放置在指定的行/列位置。 row,col
表示左上角的位置将放置形状的角[ block (0,0)
]。一个形状会如果其中一个填充 block 与一个填充 block 发生冲突,则不适合空间中现有的填充 block 或将超出范围空间。 “|”表示阻挡/障碍,而“.”指的是空旷的空间。因此,如果我将上面的形状放入空间中,它将看起来像这样:
||ee
e|.e
请问 smb 可以帮助如何将形状融入空间吗?提前致谢!
public class CreateSpace {
private int height;
private int width;
private char[][] space = new char[height][width];
private Shape originalShape;
public CreateSpace(int height, int width, char[][] space, Shape shape)
{
this.height = height;
this.width = width;
this.space = space;
this.originalShape = shape;
}
public boolean shapeFitsAt(int row, int col, Shape shape)
{
if(row < 0 || row >= height || col < 0 || col >= width)
throw new FitItException("Oops! Out of bounds in CreateSpace class! Go and check!");
else if(space[row][col] == '|' || space[row][col] == this.originalShape.getDisplayChar())
throw new FitItException("The space position is already filled out with a wall or a character. GO CHECK CreateSpace class!");
else
{
}
}
最佳答案
一种解决方案是将图案“线性化”为 2 个位集(一个用于形状,一个用于障碍物)。
在形状位集中必须保留符号的地方放 1,在其他地方放 0;在障碍物所在的位置放置 0,在“障碍物”位集中的其他位置放置 1。
例如:
..ee --> ..eee..e --> 00111001
e..e
||.. --> ||...|.. --> 00111011
.|..
然后将两个位集与,并查看结果是否与形状位集相同。如果是如果,形状适合;如果没有,至少有一个障碍物挡住了路。
Shape : 00111001
Obstacles : 00111011
AND : 00111001 == Shape bitset => OK !
快速高效,您可以重复使用障碍物位集来测试多种形状模式。
关于java - 我应该如何将形状融入空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29856423/
我有一个在 OS X 10.6.8 上运行的 NPAPI 插件,我想对其进行调试。当我使用 FireFox 3.6.19 加载它时,我可以将事件可执行文件设置为 FF,启动 FF,使用 XCode 附
我是编程新手,我按照 udemy 中的教程使用 Express JS 创建我的 Restful API。 我几乎完成了我的 API,我想将它集成到一个新的 Angular 5/6 项目中。 我已经尝试
我是一名优秀的程序员,十分优秀!