gdufe acm 1181 百度的面试
来源:互联网 发布:游族网络虚假宣传 编辑:程序博客网 时间:2024/06/11 16:51
题目链接:gdu 1181
Problem Description:
在一个二维平面,从左到右竖立n根高度分别为:a[1],a[2],….a[n],且宽度都为1的木板。试给出平面内最大的矩阵面积。
Input:
输入包含多组测试数据,每一组数据的第一行输入正整数n(<=5000),下面一行输入序列a[1],a[2],…a[n],其中1<=a[i]<=1000。
Output:
对于每一组测试数据,输出最大的矩形面积。
Sample Input:
5
6 7 3 8 9
3
2 1 4
Sample Output:
16
4
思路:
暴力可解,对每个木板,分别算出它向左延伸和向右延伸能构成的最长矩形,算出面积,更新ans。
#include <cstdio>#include <cstring>const int maxn = 5000 + 10;int a[maxn];int s[maxn];int main(){ int n; while(scanf("%d", &n) == 1){ memset(s, 0, sizeof(s)); for(int i = 0; i < n; i++) scanf("%d", &a[i]); for(int i = 0; i < n; i++){ for(int j = i; j < n; j++) if(a[i] <= a[j]) s[i] ++; else break; for(int j = i - 1; j >= 0; j--) if(a[i] <= a[j]) s[i] ++; else break; s[i] = a[i] * s[i]; } int ans = s[0]; for(int i = 1; i < n; i++) if(s[i] > ans) ans = s[i]; printf("%d\n", ans); } return 0;}
0 0
- gdufe acm 1181 百度的面试
- gdufe acm 1206 lowbit
- gdufe acm 1057 leftmost digit
- gdufe acm 1086 互质数
- gdufe acm 1121 Fibonacci数
- gdufe acm 1054 变形课
- gdufe acm 1363 校庆嘉宾
- gdufe acm 1361 校庆抽奖
- gdufe acm 1359 校庆素数
- gdufe acm 1107 Apple Collection
- 拓扑排序 gdufe acm 1183
- gdufe acm 1178 拼接数字
- gdufe acm 1014 Scramble Sort
- gdufe acm 1136 查找ACM(加强版)
- gdufe acm 1228 a*b-c
- gdufe acm 1011 Prime Ring Problem
- gdufe acm 1068 Tempter of the Bone
- GDUFE ACM-1072修理牛棚(贪心)
- 【LeetCode】Gas Station 解题报告
- python 自然语言处理
- Android ListView显示数据的常见处理方式
- 三十三 Swift3.0之 可选类型
- 飞行棋总结
- gdufe acm 1181 百度的面试
- redis使用内存info命令
- php echo 用法说明
- IKAnalyzer
- zbar条码
- Linux——userdel删除用户不完全问题
- 对HttpClient的一些封装方法
- 联发科MTK手机线刷错误代码信息解译以及解决方法大全
- jQuery获取父标签