您的位置:首页 > 其它

HRBUST 2326 Blind Father "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛

2017-05-16 19:46 337 查看
Blind Father
 
Time Limit: 1000 MSMemory Limit: 512000 K
Total Submit: 147(59 users)Total Accepted: 73(56 users)Rating:







Special Judge: No
Description
Mr. Leng, who is the predominately inheritor of buried-love family  (One of the most vogue families during your primary school maybe, anyway, this is unimportant), has such cool, cooler and coolest temperament. But, only a good ACMer can be the real leader, in other words, be admitted as a successor.

One day, a problem come to Mr. Leng 's father about carpentry. There are N pieces of planks upright the ground in one line. Each one width 1 and height uncertain.  His father wants to cut some of them and then get a rectangle. How the biggest rectangle does him can make? It too difficult to his father to solve the problem, but it is really easy for Mr. Leng. So do you. Please surmount the problem as soon as you can.

Ps: You can't move or change the posture or position of any planks.

Input
There are multiple cases. In each cases, the first line only contains an integer N, 

means the number of the planks. And the second line contains N numbers, means the height of  N planks one by one.

1<=N<=10000

Output
Please output the biggest rectangle that Mr. Leng 's father can get.
Sample Input
3
10 6 10

Sample Output
18
Hint

样例图形
Source
"尚学堂杯"哈尔滨理工大学第七届程序设计竞赛
给你n块木板,不能改变它们的顺序,问你怎样才能切出最大的长方形木板。每个木板的宽都为1。

这题直接暴力其实就能解决。先从左到右遍历这些木板。遍历过程中分别以每块木板为中心向左向右扩展。。

如果左或右边的木板的高度大于你选中的这个木板。就把宽度计入总宽度。遇到高度小于选中木板的木板。停止扩展,并记录面积大小。

最后取所有木板遍历出的最大面积值、、

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<stack>
using namespace std;

int re[10005];

int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
{
scanf("%d",&re[i]);
}

int MAX=0;
for(int i=0;i<n;i++)
{

int len=1;

for(int j=i-1;j>=0;j--)///向左扩展
{
if(re[j]>=re[i])///遇到高度大于选中木板
{
len++;///计入宽度
}
else
{
break;///否则跳出,停止扩展
}
}

for(int j=i+1;j<n;j++)///向右扩展
{
if(re[j]>=re[i])
{
len++;
}
else
{
break;
}
}

if(MAX<len*re[i])///取最大
{
MAX=len*re[i];
}

}
printf("%d\n",MAX);
memset(re,0,sizeof(re));

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM
相关文章推荐