由买买提看人间百态

topics

全部话题 - 话题: rectangle
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
j***y
发帖数: 2074
1
来自主题: JobHunting版 - 请教一个Axis-Aligned Rectangles的算法
还在看Hacking a Google Interview的材料,正看到下面这段:
Question: Axis-Aligned Rectangles
Describe an algorithm that takes an unsorted array of axis‐aligned
rectangles and
returns any pair of rectangles that overlaps, if there is such a pair. Axis-
aligned means that all the rectangle sides are either parallel or
perpendicular to the x‐ and y‐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 ... 阅读全帖
i**********e
发帖数: 1145
2
See the maximal rectangle solution explained here using step-wise
improvement:
http://www.drdobbs.com/184410529
http://www.seas.gwu.edu/~simhaweb/cs151/lectures/module6/module (search for maximal rectangle)
The optimal solution is O(M*N) (ie, the size of the rectangle). This problem
is actually very much related to this problem "Largest Rectangle in a
Histogram", which can be solved efficiently in O(N) time.
http://www.informatik.uni-ulm.de/acm/Locals/2003/html/judge.htm
Basically, the easiest w... 阅读全帖
k*******r
发帖数: 355
3
来自主题: JobHunting版 - 怎么求contour of overlapping rectangles
想起来以前碰到过一题contour of overlapping rectangles
给定a set of 可能overlapping的rectangle, 所有rectangle的底边都放在一条水平线
上,rectangle大小不一样,之间可能部分重叠,求它的外接轮廓,
这个有没有比较clean的解法
k*******r
发帖数: 355
4
来自主题: JobHunting版 - 怎么求contour of overlapping rectangles
想起来以前碰到过一题contour of overlapping rectangles
给定a set of 可能overlapping的rectangle, 所有rectangle的底边都放在一条水平线
上,rectangle大小不一样,之间可能部分重叠,求它的外接轮廓,
这个有没有比较clean的解法
D***n
发帖数: 149
5
原题是
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle
containing all ones and return its area.
变化后,只要四边全是1的rectangle,里面有0's也算..
Largest Rectangle in Histogram的方法在这好像用不上啊.
有 O ( n^2)的解法没?
s*********s
发帖数: 140
6
来自主题: JobHunting版 - 再问Maximal Rectangle的N^2解法
求能过Large Judge的N^2 Maximal Rectangle的code
http://tianrunhe.wordpress.com/2012/08/03/maximal-rectangle-wit 这个是转化为largest rectangle under histogram的N^2解法,但是过不了large judge,说是time limit exceed。自己用另外一种方法写了个N^3次方的倒是large judge能过。。。想知道能过large judge的N^2解法该怎么写。
大牛们贴一下N^2的code吧。。。
k*******r
发帖数: 355
7
来自主题: JobHunting版 - 怎么求contour of overlapping rectangles
嗯,这个链接不错,虽然是non-overlapping 的rectangle, 但overlapping rectangle
可以分解成一系列non-overlapping的rectangle,然后解法是一样的
k*******r
发帖数: 355
8
来自主题: JobHunting版 - 怎么求contour of overlapping rectangles
嗯,这个链接不错,虽然是non-overlapping 的rectangle, 但overlapping rectangle
可以分解成一系列non-overlapping的rectangle,然后解法是一样的
k*******r
发帖数: 355
9
来自主题: JobHunting版 - 怎么求contour of overlapping rectangles
嗯,这个链接不错,虽然是non-overlapping 的rectangle, 但overlapping rectangle
可以分解成一系列non-overlapping的rectangle,然后解法是一样的
k*******r
发帖数: 355
10
来自主题: JobHunting版 - 怎么求contour of overlapping rectangles
嗯,这个链接不错,虽然是non-overlapping 的rectangle, 但overlapping rectangle
可以分解成一系列non-overlapping的rectangle,然后解法是一样的
c********t
发帖数: 5706
11
想了一个笨的O(n*logn)方法
1.找到从begin到end最小值min, 得到index_min
2.则从begin index到 end index的rectangle area = min*(end-begin+1)。
3.用recursion重复1,2,计算[begin,index_min-1] 的rectangle面积和[index_min+1
,end]的面积。
过了small test, large test 在[0,1...19999]的例子,得到runtime error。
拷到eclipse测试,通过了。谁能帮我看看有什么问题。
public class Solution {
int max;
public int largestRectangleArea(int[] height) {
// Start typing your Java solution below
// DO NOT write main() function
max = 0;
if(height == null... 阅读全帖
F********9
发帖数: 44
12
Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle
containing all ones and return its area.
input output expected
["01","10"] 4 1
大伙觉得答案该是几?
w****x
发帖数: 2483
13
一直认为面试出这么难得题真是过分啊!!
================= kth element in young tablet (M+N)log(numeric range)
solution ===========
const int M = 4;
const int N = 4;
int getOrder(int A[M][N], int tg)
{
int c = 0;
int i = 0;
int j = N-1;
while (i < M && j >= 0)
{
if (A[i][j] >= tg)
j--;
else
{
c += j+1;
i++;
}
}
return c+1;
}
int getKthMin(int A[M][N], int k)
{
if (k <= 0 || k > M*N)
return INT_MIN;
int nBe... 阅读全帖
G*******s
发帖数: 10605
14
【 以下文字转载自 SmartShopper 俱乐部 】
发信人: GoRockets (火箭加油), 信区: SmartShopper
标 题: Rectangle Storage Ottoman, Black or Brown $59
发信站: BBS 未名空间站 (Sat Jul 16 12:56:26 2011, 美东)
Walmart.com has Rectangle Storage Ottoman, Black on Rollback for $59 (
original $79). Free ship to walmart stores for pick up. Excellent reviews on its spacious storage.Also available in Brown color.
http://userquote.com/forum/index.php?topic=575.msg787#msg787
G*******s
发帖数: 10605
15
【 以下文字转载自 SmartShopper 俱乐部 】
发信人: GoRockets (火箭加油), 信区: SmartShopper
标 题: 10.6-Gallon Rectangle Trash Can $18.97 at Local Walmart
发信站: BBS 未名空间站 (Wed Nov 5 04:18:53 2014, 美东)
Walmart has Better Homes and Gardens 10.6-Gallon Rectangle Trash Can for $18
.97. Currently out of order online but you can use our inventory checker to
order online and pickup In-store.
http://userquote.com/forum/index.php?topic=2588.msg3704#msg3704
i**9
发帖数: 351
16
一道老题,求最大square 可以用 DP
http://geeksforgeeks.org/?p=6257
Let the given binary matrix be M[R][C]. The idea of the algorithm is to
construct an auxiliary size matrix S[][] in which each entry S[i][j]
represents size of the square sub-matrix with all 1s including M[i][j] and
M[i][j] is the rightmost and bottommost entry in sub-matrix.
1) Construct a sum matrix S[R][C] for the given M[R][C].
a) Copy first row and first columns as it is from M[][] to S[][]
b) For other entries, use foll... 阅读全帖
i**9
发帖数: 351
17
Thanks!

(search for maximal rectangle)
problem
j********r
发帖数: 453
18
来自主题: JobHunting版 - 问个largest rectangle in histogram的问题
受前面一帖影响,看了下largest rectangle in histogram。divide and conquer的方
法很好理解,也很好code。但是linear的那个利用的stack的方法,主要思想是依次拿
array中的数与stack的top比较。但还是有些不太明白的地方,主要是如果histogram是
个倒序的,处理起来,貌似不对,例如,6,5,4,3,2,1。哪位大牛给讲讲,感激不尽
w****x
发帖数: 2483
19
来自主题: JobHunting版 - 求Leetcode OJ Maximal Rectangle的n^2解法
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle
containing all ones and return its area.
w****x
发帖数: 2483
20
来自主题: JobHunting版 - 求Leetcode OJ Maximal Rectangle的n^2解法
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle
containing all ones and return its area.
B********t
发帖数: 147
21
来自主题: JobHunting版 - 求Leetcode OJ Maximal Rectangle的n^2解法
class Solution {
public:
int maximalRectangle(vector > &matrix) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(!matrix.size())
return 0;
int start, largest = 0;
vector left(matrix[0].size(), 0);
vector right(matrix[0].size(), 0);
vector height(matrix[0].size(), 0);
for(int i = 0; i < matrix.size(); i++)
{
left[0] = 0;
righ... 阅读全帖
j******2
发帖数: 362
22
这个150上有,18.11,建立两个辅助矩阵,存每个点右边的线长和下面的线长。

rectangle
D***n
发帖数: 149
23
不是一样的吧。
150上的是sub square matrix... leetcode上的是sub rectangle啊...
s*********s
发帖数: 140
24
来自主题: JobHunting版 - largest rectangle in histogram
我看到的一种解法是用stack存短的bar,而不是存边界。http://tech-queries.blogspot.com/2011/03/maximum-area-rectangle-in-histogram.html
s*********s
发帖数: 140
25
来自主题: JobHunting版 - largest rectangle in histogram
我觉得就像http://www.informatik.uni-ulm.de/acm/Locals/2003/html/judge.html 里面说的,stack存的是started but yet unfinished subhistograms. 而且stack存的是高度的index,不是高度本身。你要是只存高度,那宽度的信息就丢失了。比如在你要得到4*5=20这个结果的时候,应该是iterate到了1,在将要弹出4的高度的时候,此时的stack应该是[3的index:0] -> [4的index:4]. 那rectangle的宽度是根据3的index0和1的index6来算的,就是6-0 - 1 = 5.
s*********s
发帖数: 140
26
来自主题: JobHunting版 - largest rectangle in histogram
我觉得就像http://www.informatik.uni-ulm.de/acm/Locals/2003/html/judge.html 里面说的,stack存的是started but yet unfinished subhistograms. 而且stack存的是高度的index,不是高度本身。你要是只存高度,那宽度的信息就丢失了。比如在你要得到4*5=20这个结果的时候,应该是iterate到了1,在将要弹出4的高度的时候,此时的stack应该是[3的index:0] -> [4的index:4]. 那rectangle的宽度是根据3的index0和1的index6来算的,就是6-0 - 1 = 5.
h****n
发帖数: 1093
27
来自主题: JobHunting版 - 再问Maximal Rectangle的N^2解法
large rectangle in histogram的变形,那个会N解法的话,自然这个就是N square解
c********t
发帖数: 5706
28
俺用了类似Largest Rectangle in Histogram,用stack达到O(M*N)的解法,依然过不
了judge large. time limit exceeded.
有人用java过了judge large的吗?
多谢!
c********t
发帖数: 5706
29
01
10
里面只有两个矩形,面积都为1

rectangle
Y********f
发帖数: 410
30
来自主题: JobHunting版 - OJ里面的Maximal Rectangle
上次有人贴了一个不是用Largest Rectangle in Histogram的方法,有人知道是哪个帖
子吗?
l**********g
发帖数: 426
31
many rectangles on plain, parallel with x, y axel
any good solution.
w*******e
发帖数: 395
32
先搜x-axis的interval是否重叠,然后再搜y-axis的interval是否重叠
两个都重叠的就是rectangle重叠
b********r
发帖数: 620
33
来自主题: JobHunting版 - 怎么求contour of overlapping rectangles
you probably can use balanced binary tree to hold heights of overlapping
rectangles
G***n
发帖数: 877
34
2年前面G家的时候,一个斜眼睛的烙印上来就给了这个题目的变种。结果就挂了。俗话
说眼斜心不正,一直都不知道这个烙印从哪里找的这个题目。后来刷leetcode的时候才
遇到这个类似的题目,其实比Maximal Rectangle还难,必须用priority queue而非
stack才能解出来。我发誓以后onsite面烙印全部都把这个题目扔出去。
v***n
发帖数: 562
35
来自主题: JobHunting版 - 求Largest Rectangle in Histogram的DP解法
看到有人提到说DP解法,但是没有想出来。
我看到O(N)的和Divid And Conquer解法
http://www.geeksforgeeks.org/largest-rectangle-under-histogram/
http://www.geeksforgeeks.org/largest-rectangular-area-in-a-hist
a***e
发帖数: 413
36
这样是不是 O(N^N)的复杂度?
class Solution {
public:
int maximalRectangle(vector > &matrix) {
int row=matrix.size();
if (row==0) return 0;
int col=matrix[0].size();
if (col==0) return 0;

//find all disjoint rectangles
vector> flag(row, vector(col,false));
int maxArea=INT_MIN;

for (int r=0; r for (int c=0; c {
int area=0;
if (matrix[... 阅读全帖
h*****y
发帖数: 218
37
来自主题: JobHunting版 - Smallest Rectangle Enclosing Black Pixels
An image is represented by a binary matrix with 0 as a white pixel and 1 as
a black pixel. The black pixels are connected, i.e., there is only one black
region. Pixels are connected horizontally and vertically. Given the
location (x, y) of one of the black pixels, return the area of the smallest
(axis-aligned) rectangle that encloses all black pixels.
For example, given the following image:
[
"0010",
"0110",
"0100"
]
and x = 0, y = 2,
Return 6.
这个题目是什么意思? 看不明白,是说能够覆盖所有黑色点的最小的矩形嘛?那x,y不
同有啥不... 阅读全帖
g*********s
发帖数: 1782
38
【 以下文字转载自 JobHunting 讨论区 】
发信人: gandjmitbbs (Nothing), 信区: JobHunting
标 题: O(NlogN) largest rectangle in histogram
发信站: BBS 未名空间站 (Sun Dec 12 18:52:53 2010, 美东)
I'm not talking about the O(N) dp solution, but the O(NlogN) one based on
the order-statistic tree here:
http://blog.csdn.net/arbuckle/archive/2006/05/06/710988.aspx
g**********y
发帖数: 14569
39
来自主题: JobHunting版 - 尘埃落定(MGF的面试总结)
赞!
试试G的题:
1. 二分找左右边界。
2. 常见题
3. 用一个collector收集结果,最底层的function:
isOverlapping(Rectangle a, Rectangle b)
collectCommon(ArrayList collector, Rectangle a, Rectangle b)
递归比较子节点,如果overlap, 进一步比较子节点,直到叶子,最后计算结果存入
collector。
4. 5.
6. DP
7. DFS
8. 计算P(i) = score(i)/sum(score[1..n]), 然后随机生成
9. 这个写起来最繁,45分钟内把头绪理清楚而且写清楚,我觉得很难,这是个大致框
架:
public class FindVertex {
ArrayList findVertices(Rectangle[] r) {
ArrayList collector = new ArrayList();
HashMap阅读全帖
b***t
发帖数: 288
40
☆─────────────────────────────────────☆
mahjong (相忘于江湖) 于 (Fri Feb 24 10:45:45 2012, 美东) 提到:
二月将尽,特推出见证牛牌活动,欢迎大家积极参与,活动暂定持续3个月。
活动要旨:估计网友参与未明麻将活动并繁荣版面,提高灌水乐趣,奖励贴图。
活动细节:参与活动者,请直接回复此帖,并附上贴图,可以是自己的牛牌,也可以是
围观是见证的牛牌,相同的牌,以发贴时间为准。参与活动者都有包子奖励,每周一评
选过去一周“周最佳牛牌“,奖励10个包子(为鼓励参与麻将,奖品将由发贴者和胡牌
着共享)。
活动评委:mahjong,unstoppable周最佳牛牌由本版网友投
票决定,最重解释权归活动评委。
5月2日新增条款
上述奖励办法不变,新增加参与奖。凡是贴牛牌的,不管是贴自己的,还是别人的,都
有20伪币的奖励,只奖励一次。目的是为了鼓励贴牌的积极性。
中奖名单如下:
9楼Mahjong 混七,2/23-2/26
31楼stoppable 混七.2/27-3/4
48楼Rectangle,backdoor... 阅读全帖
S**I
发帖数: 15689
41
☆─────────────────────────────────────☆
gzou (gzou) 于 (Thu May 12 02:26:35 2011, 美东) 提到:
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array... 阅读全帖
S**I
发帖数: 15689
42
☆─────────────────────────────────────☆
gzou (gzou) 于 (Thu May 12 02:26:35 2011, 美东) 提到:
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array... 阅读全帖
m*********t
发帖数: 527
43
http://community.topcoder.com/stat?c=problem_statement&pm=12928
Snake Snuke has N rectangles cut out of paper. The rectangles are labeled 0
through N-1. You are given int[]s X and Y with N elements each. For each i,
the sides of rectangle i have lengths X[i] and Y[i].
Snake Snuke will choose some of his rectangles and place them onto a table,
one rectangle at a time, in any order he likes. Each rectangle (except for
the first one) must overlap the immediately previous one, so at the end
Snuke wi... 阅读全帖
b*****n
发帖数: 143
44
来自主题: JobHunting版 - 请教大家一道Google的题目
刚从MIT的网站上看来的:
http://courses.csail.mit.edu/iap/interview/Hacking_a_Google_Interview_Practice_Questions_Person_A.pdf
答案如下:
Question: Axis Aligned Rectangles
Describe an algorithm that takes an unsorted array of axis‐aligned
rectangles and returns any pair of rectangles that overlaps, if there is
such a pair. Axis‐aligned means that all the rectangle sides are either
parallel or perpendicular to the x‐ and y‐axis. You can assume that each rectangle object has two variables in it: the x‐y coordinat... 阅读全帖
d***8
发帖数: 1552
45
来自主题: JobHunting版 - 请问一道面试题
题目和解法如下。 没看懂解法。
Question: Axis Aligned Rectangles
Describe an algorithm that takes an unsorted array of axis‐aligned
rectangles and returns any pair of rectangles that overlaps, if there is such
a pair.
Axis‐aligned means that all the rectangle sides are either parallel or
perpendicular to the x‐ and y‐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 coord... 阅读全帖
s*****n
发帖数: 162
46
来自主题: JobHunting版 - 问道G题(2)
Given a m * n matrix. Initially, all cells are not occupied. Write a
function allocate(x, y) (here x and y are width and height) which returns
the left-top coordinates of a
rectangle inside the matrix and marks the rectangle as occupied. All cells
of the rectangle should not be occupied when it is allocated. You do not
have to worry about the operation free().
My idea is to use a free list to record "available rectangles". When it
needs to allocate a rectangle with size (x, y), it goes through t... 阅读全帖
p*****3
发帖数: 488
47
原来java里有balanced的BST, 比C++的好用些,就是接口太多了,记不住。
写了一个求2d overlap矩形面积的题,
核心代码没多少,code都是定义各种结构各种override各种comparator去了:
public class EPI_14_20_3 {
static class Rectangle {
public int xBeg;
public int xEnd;
public int yBeg;
public int yEnd;

public Rectangle(int xb, int xe, int yb, int ye) {
xBeg = xb;
xEnd = xe;
yBeg = yb;
yEnd = ye;
}
}

static class EndPoint {
public int index... 阅读全帖
i*******t
发帖数: 499
48
来自主题: JobHunting版 - 问一道flg面试题
How about this?
Create a data structure like range tree to efficiently search for the needed
points.
For each point, create a rectangle of area zero.
Then for each rectangle containing one point, enlarge the rectangle to
contain one more point that increase the area the least. So now there are at
most n-1 rectangles each containing two points.
Then for each rectangle with two points, enlarge it again by adding another
point that still minimizing the area of that rectangle.
Repeat this until each... 阅读全帖
l******u
发帖数: 1174
49
来自主题: Programming版 - 问两个算法题, 没什么头绪
#1: Here is my idea:
Divide the non-covered area into non-overlapping rectangles, say:
L = {B1, B2, ..., Bn}
The total covered area would be total area of the table minus the sum of B1,
B2, ..., Bn. When there is no card on the table, L = {Table}, i.e., the
only rectangle is the table itself.
Drop the cards one by one. For each card Ci, there are several scenarios
where it can relate to each rectangle, Bj:
1. The card Ci does not touch Bj.
==> ignore it.
2. The card Ci contains Bj proper... 阅读全帖
s**x
发帖数: 7506
50
来自主题: JobHunting版 - CLRS interval tree 的两道练习题
14.3-4
given an interval tree T and interval i, describe how all intervals in T
that overlap i can be listed in O(min(n, klogn)) time, where k is the number
of intervals in the output list. (optional: find a solution that does not
modify the tree)
14.3-7
VLSI databases commonly represent an intergrated circuit as a list of
rectangles, assume that each rectangle is rectilinearly oriented(side
parallel to the x- and y-axis), so that a representation of a rectangle
consists of its minimum and maxim... 阅读全帖
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)