Description

Let N be the set of all natural numbers {0 , 1 , 2 , . . . }, and R be the set of all real numbers. wi, hi for i = 1 . . . n are some elements in N, and w0 = 0.  Define set B = {< x, y > | x, y ∈ R and there exists an index i > 0 such that 0 <= y <= hi ,∑0<=j<=i-1wj <= x <= ∑0<=j<=iwj}  Again, define set S = {A| A = WH for some W , H ∈ R+ and there exists x0, y0 in N such that the set T = { < x , y > | x, y ∈ R and x0 <= x <= x0 +W and y0 <= y <= y0 + H} is contained in set B}.  Your mission now. What is Max(S)?  Wow, it looks like a terrible problem. Problems that appear to be terrible are sometimes actually easy.  But for this one, believe me, it's difficult.

Input

The input consists of several test cases. For each case, n is given in a single line, and then followed by n lines, each containing wi and hi separated by a single space. The last line of the input is an single integer -1, indicating the end of input. You may assume that 1 <= n <= 50000 and w1h1+w2h2+...+wnhn < 109.

Output

Simply output Max(S) in a single line for each case.

题目大意:有n个并列的长方形,找出一个长方形,使其落下这n个长方形上,并且面积最大。

思路:不会讲……给个tips,有一些答案不可能成为最大矩形就不用算了。

代码(94MS):

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std; const int MAXN = ; struct Rectangle {
int w, h;
void read() {
scanf("%d%d", &w, &h);
}
}; Rectangle a[MAXN], t;
int ans, n; void solve() {
ans = ;
int last = ;
stack<Rectangle> stk;
for(int i = ; i < n; ++i) {
t.read();
if(last < t.h) stk.push(t);
else {
int total = ;
while(!stk.empty() && stk.top().h > t.h) {
total += stk.top().w;
ans = max(ans, stk.top().h * total);
stk.pop();
}
t.w += total;
stk.push(t);
}
last = t.h;
}
int total = ;
while(!stk.empty()) {
total += stk.top().w;
ans = max(ans, stk.top().h * total);
stk.pop();
}
} int main() {
while(scanf("%d", &n) != EOF) {
if(n == -) break;
solve();
printf("%d\n", ans);
}
}

POJ 2082 Terrible Sets(栈)的更多相关文章

  1. POJ 2082 Terrible Sets

    Terrible Sets Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 2747   Accepted: 1389 Des ...

  2. POJ 2082 Terrible Sets(单调栈)

    [题目链接] http://poj.org/problem?id=2082 [题目大意] 给出一些长方形下段对其后横向排列得到的图形,现在给你他们的高度, 求里面包含的最大长方形的面积 [题解] 我们 ...

  3. stack(单调栈) POJ 2082 Terrible Sets

    题目传送门 题意:紧贴x轴有一些挨着的矩形,给出每个矩形的长宽,问能组成的最大矩形面积为多少 分析:用堆栈来维护高度递增的矩形,遇到高度小的,弹出顶部矩形直到符合递增,顺便计算矩形面积,且将弹出的宽度 ...

  4. PKU 2082 Terrible Sets(单调栈)

    题目大意:原题链接 一排紧密相连的矩形,求能构成的最大矩形面积. 为了防止栈为空,所以提前加入元素(0,0). #include<cstdio> #include<stack> ...

  5. POJ-2081 Terrible Sets(暴力,单调栈)

    Terrible Sets Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4113 Accepted: 2122 Descrip ...

  6. POJ2082 Terrible Sets

    Terrible Sets Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5067   Accepted: 2593 Des ...

  7. Terrible Sets

    Terrible Sets Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3017   Accepted: 1561 Des ...

  8. poj2082 Terrible Sets(单调栈)

    Description Let N be the set of all natural numbers {0 , 1 , 2 , . . . }, and R be the set of all re ...

  9. poj 2082 单调栈 ***

    和poj2082差不多,加了一个宽度的条件 #include<iostream> #include<string> #include<cmath> #include ...

随机推荐

  1. java容易混淆的的内部类相关概念

    关于内部类: 作用: 1. 内部类提供了更好的封装,可以把内部类隐藏在外部类之内,不允许同一个包中的其他类访问该类 2. 内部类的方法可以直接访问外部类的所有数据,包括私有的数据 3. 内部类所实现的 ...

  2. Java集合框架之Set接口

     1.Set接口不记录元素添加顺序的误区 public  void setDemo(){        Set<String> set1 = new HashSet<>();  ...

  3. Openresty最佳案例 | 第1篇:Nginx介绍

    转载请标明出处: http://blog.csdn.net/forezp/article/details/78616591 本文出自方志朋的博客 Nginx 简介 Nginx是一个高性能的Web 服务 ...

  4. selenium之Xpath定位

    1. 绝对定位: driver.find_element_by_xpath("/html/body/div[x]/form/input") x 代表第x个 div标签,注意,索引从 ...

  5. 我的第一个Python程序

    #我的第一个Python程序 def is_valid_date(strdate): #判断是否是一个有效的日期字符串 try: #判断是否是时间格式 if ":" in strd ...

  6. HTML中footer固定在页面底部的若干种方法

    <div class="header"><div class="main"></div></div> <d ...

  7. jzoj100029. 【NOIP2017提高A组模拟7.8】陪审团(贪心,排序)

    Description 陪审团制度历来是司法研究中的一个热议话题,由于陪审团的成员组成会对案件最终的结果产生巨大的影响,诉讼双方往往围绕陪审团由哪些人组成这一议题激烈争夺. 小 W 提出了一个甲乙双方 ...

  8. CentOS上安装oracle11g报错处理

    ​ 最近,在处理oracle gateway的报错问题.只因个人的测试环境已经迁移到docker上了,又懒得装一套环境就直接在机器上安装oracle11g.今天分享的故事就从此开始-- 运行环境 项目 ...

  9. PHP接收http请求头信息

    1.PHP 自带函数 getallheaders() 目前 getallheaders() 只能用于 apache 中.如果想在 nginx 中也能使用,可以使用自定义函数. foreach (get ...

  10. 微信小程序关于tabbar点击切换数据不刷新问题

    微信小程序中经常遇到的需求就是我提交了一个表单或者进行了一个操作,需要在我的个人中心页面中实时显示出来,但是小程序中的tabbar切换类似于tab切换 并不会进行页面刷新请求 所以总是会造成一些数据更 ...