【问题标题】:Find the bars indexes in the largest Rectangular Area in a Histogram查找直方图中最大矩形区域中的条形索引
【发布时间】:2015-06-05 22:19:34
【问题描述】:
【问题讨论】:
标签:
c#
algorithm
visual-studio-2012
image-processing
【解决方案1】:
来自您发布的链接:
对于 hist[tp],“左索引”是堆栈中的前一个(在 tp 之前)项,“右索引”是“i”(当前索引)。
所以你得编辑getMaxArea()方法来存储最大区域的左右索引:
int getMaxArea(int hist[], int n)
{
// ..
int rindex=0;
int lindex=0;
while (i < n)
{
//..
if (max_area < area_with_top)
{max_area = area_with_top;
lindex=i-(max_area/hist[tp])+1;
rindex=i;
}
//..
}
while (s.empty() == false)
{
//..
if (max_area < area_with_top)
{max_area = area_with_top;
lindex=i-(max_area/hist[tp])+1;
rindex=i;
}
//..
}
//..
cout << "indexs: " << lindex << " " << rindex << "\n"; // u may pass them to main method, if needed
return max_area;
}
我不是 C++ 程序员,所以你可以优化我的尝试,
你可以在这里找到编辑后的代码:ideone: online compiler