NYoj 249
来源:互联网 发布:淘宝安装工怎样 编辑:程序博客网 时间:2024/06/06 09:43
是一道简单题了,应该说是数据比较水了。。。题目如下:
Usually, histograms are used to represent discrete distributions, e.g., the frequencies of characters in texts. Note that the order of the rectangles, i.e., their heights, is important. Calculate the area of the largest rectangle in a histogram that is aligned at the common base line, too. The figure on the right shows the largest aligned rectangle for the depicted histogram.
- 输入
- The input contains several test cases. Each test case describes a histogram and starts with an integer n, denoting the number of rectangles it is composed of. You may assume that 1 <= n <= 100. Then follow n integers h1, ..., hn, where 0 <= hi <= 100000. These numbers denote the heights of the rectangles of the histogram in left-to-right order. The width of each rectangle is 1. A zero follows the input for the last test case.
- 输出
- For each test case output on a single line the area of the largest rectangle in the specified histogram. Remember that this rectangle must be aligned at the common base line.
- 样例输入
7 2 1 4 5 1 3 34 1000 1000 1000 10000
- 样例输出
84000
下面是代码:
#include <iostream>#include <string.h>using namespace std;int main(){ int height[105],sum[105]; int n,i,j,k; while(cin>>n&&n) { memset(height,0,sizeof(height));memset(sum,0,sizeof(sum));for(i=0;i<n;++i)cin>>height[i];int count=1;for( i=1;i<n;++i){ if(height[i]<height[0]) break; count++;}sum[0]=height[0]*count;for(i=1;i<n-1;++i){ count=1; for( j=i-1;j>=0;j--) { if(height[j]<height[i])break;count++; } for( k=i+1;k<n;++k) { if(height[k]<height[i])break;count++; } sum[i]=height[i]*count;}count=1;for( i=n-2;i>=0;--i){ if(height[i]<height[n-1]) break; count++;}sum[n-1]=height[n-1]*count;int max=0;for( i=0;i<n;++i){ if(max<sum[i]) max=sum[i];}cout<<max<<endl; } return 0;}
- NYoj 249
- NYOJ 249 最大长方形
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- nyoj
- NYOJ
- NYOJ
- Cookie与会话--Session与SSO的实现细节研究
- 4,2011.9.1用户登录,更换,密码更改
- 8/31/2011 10:51:45 AM
- 数据泵导入SKIP_CONSTRAINT_ERRORS的bug(三
- _crtBreakAlloc调试内存泄漏
- NYoj 249
- VS2005内存泄漏检测方法
- oracle常用命令
- Call multiple URLs on single click of af:goLink in Oracle ADF
- VC6.0图形处理6--图像增强
- 解决VS2008程序独立运行问题
- 内存管理内幕--Jonathan Bartlett (johnnyb@eskimo.com), 技术总监, New Media Worx--
- 判断页面上控件的值是否已经改变,如果发生改变,我们就需要对其做相关处理
- WORDS AND THEIR STORIES - A Wolf in Sheep's Clothing(披着羊皮的狼)