给定一组点,我想找到一个边界框的中心(固定长度和宽度),以最大化所述框内的点数。我为实现这一目标的有效方法而感到茫然。
答案 0 :(得分:0)
这似乎是一个难题,这是我的想法: 保持图形,每个节点包含一个矩形和一个点的子集。矩形定义放置边界框的区域将与子集中的所有点重叠。
构建图表:
从保存空集和rect int total=0;
char letter='y';
while (letter == 'y')
{
Scanner userInput = new Scanner (System.in);
System.out.println("Input your number");
int number = userInput.nextInt();
total=number+total;
Scanner userInput1 = new Scanner (System.in);
System.out.println("Would you like to continue? Input y/n");
letter = userInput1.next().charAt(0); //**This is where there is an error**
}
System.out.println("The total of all the numbers inputted is "+total);
}
}
对于树中的每个点,使用根节点(伪代码)调用此递归函数:
[top:-inf, bottom:inf, left:-inf, right:inf]
现在您只需选择具有最大子集的节点,您可以在构建图表时跟踪该节点,这样您就不需要再次运行图表了。
我希望我的想法很清楚,如果我能更好地解释,请告诉我。
答案 1 :(得分:0)
复杂度为O(N ^ 2 * logN)的算法(我希望存在更好的算法):
修改:article exploiting interval trees声明O(NlogN)复杂性
按X坐标对数据阵列A进行排序
扫描A从左到右扫描线
对于A中的每个点,获取LeftX = A[k].X
- 垂直波段的左坐标,找到垂直波段RightX = LeftX + Width
的最右侧坐标。
将乐队内的点复制到另一个阵列B.
按Y坐标排序B.
扫描B宽度扫描线从上到下。
对于每个点B [i]得到TopY = B[i].Y
- 矩形的顶部坐标,计算BottomY = TopY + Height
在B中使用二进制搜索:
B [j]是B中B[j].Y <= BottomY
的最后一个底点。
查找当前矩形中的点数:
点数为N(k, i) = j - i + 1
检查N(k, i)
是否为最大值