2015-04-01 34 views

回答

0

从已发布的链接:

对于HIST [TP],“左指数”是以前的(以前以TP)项目在堆栈和“右指数”是“我'(当前指数)。

所以,你必须编辑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