博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ-2082-Terrible Sets
阅读量:7222 次
发布时间:2019-06-29

本文共 981 字,大约阅读时间需要 3 分钟。

链接:https://vjudge.net/problem/POJ-2082#author=0

题意:

挨个给n个矩形的宽和高,求内部矩形的最大面积

思路:

单调栈,每次tmp记录出栈的总宽度。记录到下一次出栈要增加的宽度。

代码:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long LL;const int MAXN = 5e4 + 10;struct Squere{ int _w; int _h;}squ[MAXN];int main(){ int n; while (scanf("%d", &n)) { if (n == -1) break; for (int i = 1;i <= n;i++) scanf("%d%d", &squ[i]._w, &squ[i]._h); stack
r; int res = 0; for (int i = 1;i <= n;i++) { int tmp = 0; while (!r.empty() && r.top()._h > squ[i]._h) { Squere f = r.top(); r.pop(); res = max(res, f._h * (f._w + tmp)); squ[i]._w += f._w; tmp += f._w; } r.push(squ[i]); } while (!r.empty()) { Squere f = r.top(); r.pop(); res = max(res, f._h * f._w); if (!r.empty()) r.top()._w += f._w; } printf("%d\n", res); } return 0;}

  

转载于:https://www.cnblogs.com/YDDDD/p/10606792.html

你可能感兴趣的文章
HTML5适应旧的浏览器的使用总结
查看>>
vi全局替换方法
查看>>
MySQL基础入门学习【1】基本操作
查看>>
初版python计算器
查看>>
CSS实现单行、多行文本溢出显示省略号(…)
查看>>
HDU 2444 The Accomodation of Students
查看>>
zabbix 源码编译安装
查看>>
:before和::before的区别
查看>>
P2261 [CQOI2007]余数求和
查看>>
浮点运算潜在的结果不一致问题
查看>>
完成端口(Completion Port)详解
查看>>
Luxand_FaceSDK_Documentation.pdf
查看>>
iOS下bound,center和frame
查看>>
sql 集合查询 数据更新操作语句
查看>>
REP 前缀
查看>>
js高级程序设计(六)面向对象
查看>>
C# JS URL 中文传参出现乱码的解决方法
查看>>
OO第三单元作业总结
查看>>
[译]从零开始成为数据科学家的9个步骤
查看>>
Python 10 MySQL数据库(一)
查看>>