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. Redis工具之Jedis

    //jedis的连接池 public void test1(){ //创建连接池配置对象 JedisPoolConfig poolConfig = new JedisPoolConfig(); poo ...

  2. 调用微信JS上传照片接口上传图片

    public ActionResult UploadImge(string serverId) { var headPath = "/UploadImage/" + DateTim ...

  3. MySQL-5.7.20主从复制测试[20180110]

    前言     MySQL 5.7.20测试主从复制   环境     主库 192.168.1.59  t-xi-sonar01     从库 192.168.1.51  t-xi-orc01   设 ...

  4. JSP/Servlet开发——第五章 使用分层实现业务处理

    1.JNDI(Java Naming and Directory Interface)Java命名和目录接口: ●JNDI:是一个有关应用序设计的 API 为开发人员提供了查找和访问各种命名和目录服务 ...

  5. idea中注解配置一对多,多对一,双向多对一映射(不详细)

    一对多 package cn.pojo; import javax.persistence.*; import java.io.Serializable; import java.util.Set; ...

  6. java程序执行命令行,解锁数据库表

    有些表锁的时间长或其他原因,在plsql中不能解锁,只能用命令行解锁. 有些功能跨平台系统的交互偶尔会锁表,就需要自动解锁. 下面是解锁的代码: package com.lg.BreakOracleU ...

  7. 来自一枚初生牛犊不怕虎的小菜鸟的Mock.js使用,不足之处欢迎读者的指出 谢谢

    本文章写的是基于require的mock.js的几种常用生成随机数据和ajax模拟前后端的交互信息 <script src="./app/libs/require.js"&g ...

  8. angularjs Directive自定义指令详解

    作用:需要用Directive有下面的情景: 1.使你的Html更具语义化,不需要深入研究代码和逻辑即可知道页面的大致逻辑. 2. 抽象一个自定义组件,在其他地方进行重用. 3.使用公共代码,减少重复 ...

  9. Nodejs 使用 SerialPort 调用串口

    工作经常使用串口读写数据,electron 想要替代原来的客户端,串口成了必须要突破的障碍. get -->  https://github.com/EmergingTechnologyAdvi ...

  10. Electronic Devices【电子设备】

    Electronic Devices We may think we're a culture that gets rid of our worn technology at the first si ...