“常用公式”在线计算,“设计手册”在线查询
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 支持支持 反对反对

共 1 个关于本帖的回复 最后回复于 2013-7-30 17:03

沙发
邢城 新来的 发表于 2013-7-30 17:03:08 | 只看该作者
研发埠培训中心
Axis‐aligned means that all the rectangle sides are either parallel or perpendicular to the x‐andy‐axis.You can assume that each rectangle object has two variables in it:the x‐y coordinates of the upper‐left corner and the bottom‐right corner.Good Answer:Create a sorted array of the x coordinates of the left and right edges of the rectangles.Then,use a "scanline" to move from left to right through the rectangles.Keep a binary search tree containing they coordinates of the top and bottom edges of the rectangles that over lap the scanline.For each element of the array,check whether it is a left or right edge.If it is a right edge,remove the corresponding top and bottom edges from the BST.If it is a left edge,search the BST for rectangles that over lap the current rectangle;if there is one,return the overlap.Then,add they coordinates of the top and bottom edges of the rectangle to the BST.The search takes O(nlogn) time,since it takes O(nlogn) time to sort the rectangles and each of the 2nd iterations takes O(logn) time.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注我们

360网站安全检测平台