Redian新闻
>
现实生活中的男人其实应该挺喜欢罗子君的
avatar
现实生活中的男人其实应该挺喜欢罗子君的# TVChinese - 中文电视
s*n
1
今天分享的是我们家的“救急”菜谱。偶尔白天没时间解冻腌制肉类,结果又回家晚
了的时候用微波炉解冻肉末的同时切红葱,然后起锅炒熟就好,能保证短时间内吃上
饭。另外这个菜适合速冻,所以不论是偷懒不想做饭的时候还是给孩子带饭都是很好
的选择,属于我们家冷冻室的常客。
说到米饭,现在都流行多吃粗粮,薯条家吃糙米饭也有好几年了。记得刚买回糙米的
时候,因为听好多人说糙米饭不好吃,所以我们都是混着白米一起煮的。可是糙米的
部分硬硬地夹生状很影响口感,多放水没什么帮助不说,反而让白米饭变得特别软烂
,两者变得都不好吃。有听说全部用糙米煮出来的饭很好吃,可是我们家的电饭锅是
最简单的,按键压下去开始煮,煮好了按键就弹起那种,没有高级电饭锅分类烹煮的
功能。直到有一回在饼版看到有人分享煮糙米的简便方法,试过之后果然很好用:
那就是在煮糙米的时候(全部都用糙米哦,不要混别的米)多加点水,差不多是煮同
等量的白米饭所用水量的1.5-2倍。冷水就可以,生的糙米也不需要提前浸泡,淘好
米可以马上开始煮。水量的差异跟米的品种,还有电饭锅的密闭性能都有关系。喜欢
米饭口感硬些的就从1.5倍开始试,喜欢米饭软些的就从2倍水量开始尝试,然后根据
结果做调整。自打发现这个方法之后,我们家就没怎么买过白米了。吃惯了糙米饭,
觉得韧韧的有嚼劲还特别香,偶尔在外面吃到白米饭还有点不习惯呢。
【红葱肉燥饭】
称量单位说明:1大勺=15毫升,1小勺=5毫升
原料:
肉末 500克
红葱头(Shallot) 10个
蒜3-4瓣
白兰地酒(Brandy) 1大勺
糖 1-3小勺
生抽酱油 3大勺
老抽酱油 1-2小勺
白胡椒粉 1/4小勺
五香粉 1/4小勺
盐适量
水适量
香油适量
米饭适量
做法:
1.红葱头去皮之后切碎;蒜剁蓉备用。
2.炒锅烧热,加少许油后下红葱末翻炒至软,加蒜末炒出香味后下肉末翻炒。
3.加入白兰地酒及除香油外的所有调味料,边炒边用铲刀把肉末戳碎。
4.加适量水后加盖焖煮三五分钟至肉末熟,淋香油拌匀后起锅,趁热浇在米饭或面条
上即可食用。
说明:
1.这道菜我用猪肉末、牛肉末还有鸡肉末都做过,都很好吃。如果超市的肉类柜台提
供绞肉服务,可以请他们处理成粗绞肉,口感会更好些。
2.红葱头是个头比较小的洋葱,风味很特别,如果没有的话用洋葱也是可以的,味道
稍微逊色一些。
3.红葱末炒到软就可以了,当然也可以多炒一会儿至焦化(Caramelized)有微微的
甜味。
4.煮的时候汤汁不要收太干哦,拌饭或者面条吃的时候滋味更好。
5.图片中卤蛋的做法请看:
http://blog.sina.com.cn/s/blog_9aab16e5010102a5.html
【薯条家的厨房】
http://blog.sina.com.cn/ximushutiao
avatar
g*s
2
当年同事去google面试的题目。
给你n个数字a1,a2...an,表示坐标上面(i,ai)个点,i=1.. n
(i,ai)到(i,0)共n个线段,从中挑两条,和x轴一起构成一个容器,让容器能装
的液体容量最大
(容器不能倾斜)。
大家先做做
avatar
b*u
3
我小时候左邻右舍的女孩子都差不多是这样的,基本都是江浙沪女孩子,人漂亮,生活
很精致的。你以为只会玩,其实做起事来很认真的。像罗子君那样,女人味很足,很真
实,虽然势力但也很能干的。唐靖那样的,男人不喜欢的,太自我了,太较劲了。
反正我是眼都不眨一下就会选择罗子君这样的。
avatar
c*u
4
喜欢!
avatar
g*s
5
这不就是maximum rectangle in histogram吗。

【在 g***s 的大作中提到】
: 当年同事去google面试的题目。
: 给你n个数字a1,a2...an,表示坐标上面(i,ai)个点,i=1.. n
: (i,ai)到(i,0)共n个线段,从中挑两条,和x轴一起构成一个容器,让容器能装
: 的液体容量最大
: (容器不能倾斜)。
: 大家先做做

avatar
l*e
6
嗯哪,我家买的糙米米袋子上有写同样的做法呢,不过我家那锅还是不给力,密闭性机
器有问题,都想再败个好点的了。

【在 s**n 的大作中提到】
: 今天分享的是我们家的“救急”菜谱。偶尔白天没时间解冻腌制肉类,结果又回家晚
: 了的时候用微波炉解冻肉末的同时切红葱,然后起锅炒熟就好,能保证短时间内吃上
: 饭。另外这个菜适合速冻,所以不论是偷懒不想做饭的时候还是给孩子带饭都是很好
: 的选择,属于我们家冷冻室的常客。
: 说到米饭,现在都流行多吃粗粮,薯条家吃糙米饭也有好几年了。记得刚买回糙米的
: 时候,因为听好多人说糙米饭不好吃,所以我们都是混着白米一起煮的。可是糙米的
: 部分硬硬地夹生状很影响口感,多放水没什么帮助不说,反而让白米饭变得特别软烂
: ,两者变得都不好吃。有听说全部用糙米煮出来的饭很好吃,可是我们家的电饭锅是
: 最简单的,按键压下去开始煮,煮好了按键就弹起那种,没有高级电饭锅分类烹煮的
: 功能。直到有一回在饼版看到有人分享煮糙米的简便方法,试过之后果然很好用:

avatar
g*s
7
haha. 原来是老题。
这题作为acm试题基本就是送分啊

【在 g*********s 的大作中提到】
: 这不就是maximum rectangle in histogram吗。
avatar
M*8
8
哈喇子……
avatar
g*s
9
对没受过训练的人来说还是有难度。

【在 g***s 的大作中提到】
: haha. 原来是老题。
: 这题作为acm试题基本就是送分啊

avatar
c*n
10
avatar
H*M
11
it is different

【在 g*********s 的大作中提到】
: 这不就是maximum rectangle in histogram吗。
avatar
b*a
12
难道不就是多加水么。。。

【在 s**n 的大作中提到】
: 今天分享的是我们家的“救急”菜谱。偶尔白天没时间解冻腌制肉类,结果又回家晚
: 了的时候用微波炉解冻肉末的同时切红葱,然后起锅炒熟就好,能保证短时间内吃上
: 饭。另外这个菜适合速冻,所以不论是偷懒不想做饭的时候还是给孩子带饭都是很好
: 的选择,属于我们家冷冻室的常客。
: 说到米饭,现在都流行多吃粗粮,薯条家吃糙米饭也有好几年了。记得刚买回糙米的
: 时候,因为听好多人说糙米饭不好吃,所以我们都是混着白米一起煮的。可是糙米的
: 部分硬硬地夹生状很影响口感,多放水没什么帮助不说,反而让白米饭变得特别软烂
: ,两者变得都不好吃。有听说全部用糙米煮出来的饭很好吃,可是我们家的电饭锅是
: 最简单的,按键压下去开始煮,煮好了按键就弹起那种,没有高级电饭锅分类烹煮的
: 功能。直到有一回在饼版看到有人分享煮糙米的简便方法,试过之后果然很好用:

avatar
g*s
13
you are right. i didnt read the "maximum rectangle in histogram"
carefully.
but we can also find a O(n) for this question.

【在 H*M 的大作中提到】
: it is different
avatar
g*A
14
饿
avatar
f*i
15
DP?
假设input是一个数组,从0到n,那么我们要的是以下三种情况中最大的那个
for the ith and jth position
1) min(a[i],a[j])*(j-i)
2) min(a[i+1],a[j])*(j-i-1)
3) min(a[i],a[j-1])*(j-i-1)
i一开始从0, j一开始从n
按照这样不断DP 递归去找最大的,时间复杂度应该还是O(n)
avatar
f*i
16
JAVA代码如下:
另外,如果ai可以是负数,那么一开始就要分割为正数和负数两个不同的数列,同时用0代
替异常的数,比如:{1,-4,5,-3,-6,6,7}
=> {1,0,5,0,0,6,7} and {0,-4,0,-3,-6,0,0},然后对负数列取绝对值.
public static int array_maximum_bucket(int [] arr, int start, int end){
if(start>=end)
return 0;
int height = arr[start]>=arr[end]?arr[end]:arr[start];
return find_max(height*(end-start),array_maximum_bucket(arr, start+1,
end),array_maximum_bucket(arr,start,end-1));
}

public static int find_max(int i, int j, int k){
int max = i;
if(j>max)
max = j;
if(k>max)
max = k;
return max;
}
avatar
b*h
17
你这个是O(n^2)的吧

【在 f*********i 的大作中提到】
: DP?
: 假设input是一个数组,从0到n,那么我们要的是以下三种情况中最大的那个
: for the ith and jth position
: 1) min(a[i],a[j])*(j-i)
: 2) min(a[i+1],a[j])*(j-i-1)
: 3) min(a[i],a[j-1])*(j-i-1)
: i一开始从0, j一开始从n
: 按照这样不断DP 递归去找最大的,时间复杂度应该还是O(n)

avatar
b*k
18
O(nlog(n)) solution:
Using DP in general:
sort (i, ai) by ai take O(nlog(n))
got (i_1, ai_1), (i_2, ai_2), .... (i_n, ai_n)
where ai_1 >= ai_2 >= ... ai_n
then keep a minHeap and maxHeap for i_k
maxInfo.cap = -INF;
for (each i_k from (i_1 to i_n))
i_min = minHeap.getMin();
i_max = maxHeap.getMax();
tmpCap = ai_k*(max(abs(i_k - i_min), abs(i_k - i_max)))
if (tmpCap > maxInfo.cap)
maxInfo.cap = tmpCap
//book keeping the i_k, and i_min or i_max
minHeap.insert(i_k) //log(n)
maxHeap.insert(i_k) //log(n)
end
Thinking hard for an O(n) solution, anyone knows?

【在 g***s 的大作中提到】
: 当年同事去google面试的题目。
: 给你n个数字a1,a2...an,表示坐标上面(i,ai)个点,i=1.. n
: (i,ai)到(i,0)共n个线段,从中挑两条,和x轴一起构成一个容器,让容器能装
: 的液体容量最大
: (容器不能倾斜)。
: 大家先做做

avatar
b*k
19
don't need to maintain heaps, just maintain the value of max and min of
i_k has been scanned so for.
Anyway, the sort part takes O(nlog(n))

【在 b*k 的大作中提到】
: O(nlog(n)) solution:
: Using DP in general:
: sort (i, ai) by ai take O(nlog(n))
: got (i_1, ai_1), (i_2, ai_2), .... (i_n, ai_n)
: where ai_1 >= ai_2 >= ... ai_n
: then keep a minHeap and maxHeap for i_k
: maxInfo.cap = -INF;
: for (each i_k from (i_1 to i_n))
: i_min = minHeap.getMin();
: i_max = maxHeap.getMax();

avatar
y*5
20
Brute Force: O(n^2)
D & C: O(nlgn)
Stack linear search: O(n)
It is an ACM question.
You can get the explanation here: http://www.informatik.uni-ulm.de/acm/Locals/2003/html/judge.html

【在 b*k 的大作中提到】
: O(nlog(n)) solution:
: Using DP in general:
: sort (i, ai) by ai take O(nlog(n))
: got (i_1, ai_1), (i_2, ai_2), .... (i_n, ai_n)
: where ai_1 >= ai_2 >= ... ai_n
: then keep a minHeap and maxHeap for i_k
: maxInfo.cap = -INF;
: for (each i_k from (i_1 to i_n))
: i_min = minHeap.getMin();
: i_max = maxHeap.getMax();

avatar
y*5
22
You should not expect the interviewer asks the question without changing a
word.

【在 u******e 的大作中提到】
: 都说不是直方柱内接矩形问题了
avatar
g*y
23

有非stack的o(n)方法,我以前没看stack的solution时候想到的,不过现在没太多时间
码字。
大概的基本思路就是,考虑这个问题:现在你要做的是,寻找并记录下:对于直方图的
每一个bar,左边第一个比它更高的
bar的位置 + 右边第一个比它更高的bar的位置。

【在 g***s 的大作中提到】
: 当年同事去google面试的题目。
: 给你n个数字a1,a2...an,表示坐标上面(i,ai)个点,i=1.. n
: (i,ai)到(i,0)共n个线段,从中挑两条,和x轴一起构成一个容器,让容器能装
: 的液体容量最大
: (容器不能倾斜)。
: 大家先做做

avatar
u*e
24
input
2 1 2
in histogram result is 3 (width=3 * height*1)
in this question result is 4 (width=2 * height*2)
how do you use stack?

【在 y******5 的大作中提到】
: You should not expect the interviewer asks the question without changing a
: word.

avatar
y*5
25
Hint:
If input 2, 1, 2
there is only 1 bar
if input 1, 2, 3 or 3, 2, 1
there are 2 bars

【在 u******e 的大作中提到】
: input
: 2 1 2
: in histogram result is 3 (width=3 * height*1)
: in this question result is 4 (width=2 * height*2)
: how do you use stack?

avatar
b*y
26
什么是bar

【在 y******5 的大作中提到】
: Hint:
: If input 2, 1, 2
: there is only 1 bar
: if input 1, 2, 3 or 3, 2, 1
: there are 2 bars

avatar
u*e
27
还是不太明白

【在 y******5 的大作中提到】
: Hint:
: If input 2, 1, 2
: there is only 1 bar
: if input 1, 2, 3 or 3, 2, 1
: there are 2 bars

avatar
y*5
28
Sorry for confusing. I mean histogram. "bar" is from bar chart.

【在 b*******y 的大作中提到】
: 什么是bar
avatar
u*e
29
could you explan more detail how to solve case
2 1 2
in this problem with stack?

【在 y******5 的大作中提到】
: Sorry for confusing. I mean histogram. "bar" is from bar chart.
avatar
y*5
30
I mean, we need to find a way to construct histogram, and we can start from
min of leftmost and rightmost. Suppose current value a[i] is no less than
next value (a[i-1] or a[i+1]), then overwrite the next value with a[i]. At
the end, you will have n-1 histograms.

【在 u******e 的大作中提到】
: 还是不太明白
avatar
y*5
31
Sorry guys, my previous construction method is not correct. New method to
construct histogram is:
Step:
1. maintain 3 variables: left, right, min. left =1, right=n, min_height=0
2. min_height = min(a[left], a[right])
3. if min_height == a[left], left++ until a[left] > min_height, and all
elements just scaned are assigned to min_height;
else if min_height == a[right], right-- until a[right] > min_height, and
all elements just scaned are assigned to min_height;
4. goto step 2 until left + 1 = right. Suppose a[left] > a[right], then a[
left] = a[right]
Now we have n-1 histograms. Please correct me if I am wrong.

from

【在 y******5 的大作中提到】
: I mean, we need to find a way to construct histogram, and we can start from
: min of leftmost and rightmost. Suppose current value a[i] is no less than
: next value (a[i-1] or a[i+1]), then overwrite the next value with a[i]. At
: the end, you will have n-1 histograms.

avatar
u*e
32
明白了

from

【在 y******5 的大作中提到】
: I mean, we need to find a way to construct histogram, and we can start from
: min of leftmost and rightmost. Suppose current value a[i] is no less than
: next value (a[i-1] or a[i+1]), then overwrite the next value with a[i]. At
: the end, you will have n-1 histograms.

avatar
y*5
33
In your case, a[1] == a[3] == 2, so we just start from a[1] and move
rightward. a[2] is less than 2, so assign 2 to a[2]. Because a[2] and a[3]
are adjacent, we stop here and will have {2,2,2}, which can be seen as two
histograms.

【在 u******e 的大作中提到】
: could you explan more detail how to solve case
: 2 1 2
: in this problem with stack?

avatar
m*g
34
弱问,这是立体坐标么? 没看懂怎么跟x轴形成立体矩形..

a1
0 .......i........

a2
..an
thanks

这不就是maximum rectangle in histogram吗。

【在 g*********s 的大作中提到】
: 这不就是maximum rectangle in histogram吗。
avatar
h*3
35

我想的一个方法,大家看看。
先拿 (1,a1) 和 (n,an) 这2个点,计算容量,(假设a1<=an), 那就是
a1 * (n-1), 存为当前最大 CurMax, i.e. CurMax = a1 * (n-1)
然后我们从小的那个边开始扫,a1小,就看a3,一直到某个ai, ai>a1, 这时计算容量, temp = min(ai,an)*(n-i),
CurMax = max(CurMax,temp); 再看ai 和an 哪个小,如果ai小,接着往下扫 a(i+1).
.. 只知道某个数aj , aj> ai; 如果an小,就看 a(n-1)...知道某个数 ak, ak>an.
然后再计算容量,更新CurMax。 重复做这些,直到两条边重合。CurMax里存的就是最
大的容量。
复杂度 O(n).


【在 g***s 的大作中提到】
: 当年同事去google面试的题目。
: 给你n个数字a1,a2...an,表示坐标上面(i,ai)个点,i=1.. n
: (i,ai)到(i,0)共n个线段,从中挑两条,和x轴一起构成一个容器,让容器能装
: 的液体容量最大
: (容器不能倾斜)。
: 大家先做做

avatar
s*y
36
Seems not right
given the following input
4, 3, 1, 2, 5
Your first CurMax is already wrong value le.
Look at this:
http://www.informatik.uni-ulm.de/acm/Locals/2003/html/histogram

a1
).

【在 h*********3 的大作中提到】
:
: 我想的一个方法,大家看看。
: 先拿 (1,a1) 和 (n,an) 这2个点,计算容量,(假设a1<=an), 那就是
: a1 * (n-1), 存为当前最大 CurMax, i.e. CurMax = a1 * (n-1)
: 然后我们从小的那个边开始扫,a1: 小,就看a3,一直到某个ai, ai>a1, 这时计算容量, temp = min(ai,an)*(n-i),
: CurMax = max(CurMax,temp); 再看ai 和an 哪个小,如果ai小,接着往下扫 a(i+1).
: .. 只知道某个数aj , aj> ai; 如果an小,就看 a(n-1)...知道某个数 ak, ak>an.
: 然后再计算容量,更新CurMax。 重复做这些,直到两条边重合。CurMax里存的就是最
: 大的容量。

avatar
h*3
37
前面有人已经提过了,这提不是那个经典的 histogram题目。
你的例子,最大值是16. 就是4和5和x轴形成的容器。

【在 s*****y 的大作中提到】
: Seems not right
: given the following input
: 4, 3, 1, 2, 5
: Your first CurMax is already wrong value le.
: Look at this:
: http://www.informatik.uni-ulm.de/acm/Locals/2003/html/histogram
:
: a1
: ).

avatar
s*y
38
o, you are right.
Then it is actually easier than the ACM question.

【在 h*********3 的大作中提到】
: 前面有人已经提过了,这提不是那个经典的 histogram题目。
: 你的例子,最大值是16. 就是4和5和x轴形成的容器。

avatar
j*j
39
恩,这个跟直方图问题不一样
如果ai是负数,那么它参与构成的容器盛不住液体,这些数一定得过滤掉;所以我们不
妨简单化一下,假定ai都是positive的
可以用两个queue来做,q1, q2
先做1->n的loop, 根据逐次增大的ai 把(i, ai) push 到 q1
再做n->1的loop, 也根据逐次增大的ai 把 (i, ai) push 到 q2
同时从q1和q2 pop Aq11, Aq21,计算构成的rectangle面积,作为初始的最大容积max;
比较Aq11和Aq21的大小,pop小的所对应的queue, 假定pop出Aq12, 计算出Aq12和Aq21
的rectangle面积,跟max比较,大的话就替代max;
这样一直做下去,直到最后q1,q2为空

【在 g***s 的大作中提到】
: 当年同事去google面试的题目。
: 给你n个数字a1,a2...an,表示坐标上面(i,ai)个点,i=1.. n
: (i,ai)到(i,0)共n个线段,从中挑两条,和x轴一起构成一个容器,让容器能装
: 的液体容量最大
: (容器不能倾斜)。
: 大家先做做

avatar
g*s
40
31楼和27楼其实是一个意思。
ACM那题是不同的一题,其实可以用我们熟悉大DP来解
1 求all b(x), b(x)=在x右边第一比ax小的位置 [b(x)=n+1 if all are larger than
ax] O(n) using DP
2 求all c(x), c(x)=在x左边最后一个比ax小的位置[c(x)=0 if all are larger than
ax] O(n) using DP
3 d(x) = (b(x) - c(x) -1) * ax O(n)
4 return max(d(x))
avatar
g*i
41
这题和largest rectangle of histogram 不是一回事,但很简单,有 O(n)算法。
The principle of optimization is: any A[k]>= min(A[optimal_left], A[optima_
right]) must satisfy optimal_left<=k<=optimal_right
(1)scan the array A[], find two elements (A[current_left], A[current_right
]) with largest and second largest value respectively, set the current
optimal area as min(A[current_left], A[current_right])*(current_right-
current_left)
(2) scan the array A[] again, test if the select element can replace the A[
current_left] when its index is smaller than current_left, otherwise, if can
replace the A[current_right], by comparing the area with the current
optimal area
(3) finally the current_left and current_right is the optimal.

【在 g***s 的大作中提到】
: 当年同事去google面试的题目。
: 给你n个数字a1,a2...an,表示坐标上面(i,ai)个点,i=1.. n
: (i,ai)到(i,0)共n个线段,从中挑两条,和x轴一起构成一个容器,让容器能装
: 的液体容量最大
: (容器不能倾斜)。
: 大家先做做

avatar
g*s
42
这个不对。

A[optima_
A[current_right
the A[
can

【在 g*****i 的大作中提到】
: 这题和largest rectangle of histogram 不是一回事,但很简单,有 O(n)算法。
: The principle of optimization is: any A[k]>= min(A[optimal_left], A[optima_
: right]) must satisfy optimal_left<=k<=optimal_right
: (1)scan the array A[], find two elements (A[current_left], A[current_right
: ]) with largest and second largest value respectively, set the current
: optimal area as min(A[current_left], A[current_right])*(current_right-
: current_left)
: (2) scan the array A[] again, test if the select element can replace the A[
: current_left] when its index is smaller than current_left, otherwise, if can
: replace the A[current_right], by comparing the area with the current

avatar
n*t
43

than
than
b(x)怎样DP能O(n)?

【在 g***s 的大作中提到】
: 31楼和27楼其实是一个意思。
: ACM那题是不同的一题,其实可以用我们熟悉大DP来解
: 1 求all b(x), b(x)=在x右边第一比ax小的位置 [b(x)=n+1 if all are larger than
: ax] O(n) using DP
: 2 求all c(x), c(x)=在x左边最后一个比ax小的位置[c(x)=0 if all are larger than
: ax] O(n) using DP
: 3 d(x) = (b(x) - c(x) -1) * ax O(n)
: 4 return max(d(x))

avatar
d*l
45
我得想法和27楼差不多。
我觉得两边可以维护一个起始和结束的指针l和r.这个问题的一个性质是,如果某个bar
的左边有比它高的bar,那最优解必然不可能以它为起始,因为我们总能把边界再往左
扩,所以l递增的时候可以直接略过比当前最大值小的那些ai,相当于只检查一个递增
的序列。对于每个要检查的元素,结束指针r要往回退到第一个大于等于al的元素,对
经过的所有元素都尝试更新最大值。这样两边的指针相遇就停止,复杂度是O(n).
avatar
g*e
46
/**
Maintain two pointers, head and tail,
1. start sweeping the array from head if a[head]otherwise
2. for each a[i], if current value is less or equal to a[head] (or a[tail]),
skip
3. else compute area with a[i] & a[tail] (or a[head]), set start=i (or stop=
i), update max volume if necessary
4. until head meets tail, return max volume
All items are scanned at most once, total time O(n).
*/
public static int maxVolume(int[] a) {
if (a.length<=1)
return 0;

int maxVolume = 0;
int start = 0, end = a.length-1;
int maxStart = 0, maxStop = a.length-1;

maxVolume = Math.min(a[start], a[end]) * (end - start);

while (start//move start pointer
if (a[start]int i = start;
//move forward for all a[i]<=a[start]
while (ii++;

if (i==end)
break;
else {
//a[i]>a[start], compare volumn
int tmp = Math.min(a[i], a[end]) * (end-i);
if ( tmp>maxVolume ) {
maxVolume = tmp;
maxStart = i;
}
start = i; //update start pointer to i
}

} else { //move end pointer
int i = end;
//move backward for all a[i]<=a[end]
while (i>start && a[i]<=a[end])
i--;

if (i==start)
break;
else {
//a[i]>a[end], compare volumn
int tmp = Math.min(a[i], a[start]) * (i-start);
if ( tmp > maxVolume ) {
maxVolume = tmp;
maxStop = i;
}
end = i; //update stop poniter to i
}
}
}

System.out.println("\nmax volume = " + maxVolume + ", start=" +
maxStart + ", end=" + maxStop);


return maxVolume;
}
avatar
g*i
47
那不对,给个反例来

【在 g***s 的大作中提到】
: 这个不对。
:
: A[optima_
: A[current_right
: the A[
: can

avatar
g*s
48
3 5 1 5 3

【在 g*****i 的大作中提到】
: 那不对,给个反例来
avatar
B*M
49
大家看看这个怎么样?
double maxArea(double a[], int size){
int left = 0;
int right = size - 1;
double area = min(a[left], a[right]) * (right - left);
while(left < right){
double temp = min(a[left], a[right]) * (right - left);
area = temp > area ? temp :area;
if(a[left] < a[right]){
double t = a[left];
while(a[left] <= t && left < right){
left ++;
}
} else {
double t = a [right];
while(a[right] <= t && left < right){
right --;
}
}
}
return area;
}

【在 g***s 的大作中提到】
: 3 5 1 5 3
avatar
B*M
50
您老这思路和我老是一样的,

a1
).

【在 h*********3 的大作中提到】
: 前面有人已经提过了,这提不是那个经典的 histogram题目。
: 你的例子,最大值是16. 就是4和5和x轴形成的容器。

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。