poj 2082——Terrible Sets
来源:互联网 发布:mysql update join on 编辑:程序博客网 时间:2024/04/27 20:18
题意:求给出矩形中能找出最大矩形的面积
思路:给出n组wi,hi,每给出一组wi,hi相当于在沿x轴方向加上一个长wi,高hi的矩形。B集合中<x,y>即这些矩形中的点。T集合是横坐标从x0到x0+W,纵坐标从y0到yo+H中的点的集合,并且要求T集合中的点全部在B集合内。求满足条件的T集合中W*H最大的那一组。
代码如下:
#include<cstdio>#include<cstring>#include<iostream>using namespace std;struct rec{ int w; int h;};rec s[50005];int tot;int main(){ // freopen("data.txt","r",stdin); int n; while(scanf("%d",&n)) { if(n==-1)break; tot=0; int ans=0; int last=0; for(int i=0;i<n;++i) { rec tmp; scanf("%d%d",&tmp.w,&tmp.h); if(tmp.h>=last) { s[tot++]=tmp; last=tmp.h; continue; } int width=0; while(tot>=0) { rec &top=s[tot-1]; // cout<<i<<' '<<tot<<' '<<top.h<<' '<<top.w<<endl;; if(top.h<=tmp.h||tot==0) { s[tot].w=width+tmp.w; s[tot].h=tmp.h; // cout<<"???"<<tot+1<<' '<<width<<' '<<tmp.h<<endl; tot++; break; } else{ width+=top.w; ans=max(ans,width*top.h); tot--; } } last=tmp.h; } int width=0; // for(int i=0;i<tot;++i)cout<<s[i].w<<' '<<s[i].h<<endl; while(tot>0) { // cout<<tot<<' '<<s[tot-1].w<<' '<<s[tot-1].h<<endl; width+=s[tot-1].w; ans=max(ans,width*s[tot-1].h); tot--; } printf("%d\n",ans); } return 0;}
0 0
- poj 2082——Terrible Sets
- POJ 2082 Terrible Sets
- poj 2082 Terrible Sets
- POJ 2082 Terrible Sets
- POJ 2082 Terrible Sets
- POJ 2082Terrible Sets
- poj 2082 Terrible Sets
- POJ 2082 Terrible Sets
- POJ 2082 Terrible Sets
- poj 2082 Terrible Sets
- poj 2082 Terrible Sets
- POJ 2082 Terrible Sets
- Terrible Sets——poj-2082——单调栈
- poj 2082 Terrible Sets (数据结构 ——栈 STL)
- POJ 2082 Terrible Sets(栈)
- POJ 2082 Terrible Sets(单调栈)
- POJ-2082 Terrible Sets (单调栈)
- POJ 2082 Terrible Sets 单调栈
- java设计模式之中介者模式
- HDU 5008 Boring String Problem 后缀数组
- 虚方法【只有虚方法或者抽象方法才能被子类方法重写】
- 常用代码段Android Shortcut操作(快捷方式)
- 【北京站】IT运维免费培训火爆进行时,还有惊喜礼品哦~
- poj 2082——Terrible Sets
- 创建指定时间段内的日历信息
- 恢复出厂设置壁纸偏移patch
- 储存器-大端模式与小端模式
- IOS判断是否有效银行卡号
- 教育行业OA办公系统
- spring jdbc 事务配置----TransactionTemplate使用
- 面向对象中的顶级装备《多态》
- Non-terminating decimal expansion; no exact representable decimal result