题意:

给你一幅图,问你第二大矩形面积是多少。

思路:

直接一行行跑stack求最大矩阵面积的经典算法,不断更新第二大矩形面积,注意第二大矩形可能在第一大矩形里面。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define mem(a,b) memset(a,b,sizeof(a))
#define fo(a,b,c) for(a=b;a<=c;++a)//register int i
#define fr(a,b,c) for(a=b;a>=c;--a)
#define pr printf
#define sc scanf
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int); struct node
{
int h,l;
};
stack<node> S;
int n,m;
int Nextl[N][N];
char mp[N][N];
//----------------------------------------------------- int main()
{
sc("%d%d",&n,&m);
for(int i=;i<=n;++i)
sc("%s",mp[i]+);
for(int j=;j<=m;++j)
{
int pos=n;
for(int i=n;i>=;--i)
{
if(mp[i][j]=='')
pos=-;
else
{
if(pos==-)
Nextl[i][j]=,pos=i;
else
Nextl[i][j]=pos-i+;
}
}
}
int ans1=,ans2=;
int ll=,rr=;
for(int i=;i<=n;++i)
{
for(int j=;j<=m;++j)
{
node temp;
temp.h=Nextl[i][j];
temp.l=;
if(S.empty())
S.push(temp);
else
{
int L=;
while(!S.empty()&&temp.h<=S.top().h)
{
L+=S.top().l;
int t=L*S.top().h;
if(t>ans1)
{
ans2=ans1;
ll=L,rr=S.top().h;
ans1=t;
}
else
{
if(t>=ans2)
ans2=t;
}
S.pop();
}
temp.l+=L;
S.push(temp);
}
}
int L=;
while(!S.empty())
{
L+=S.top().l;
int t=L*S.top().h;
if(t>ans1)
{
ll=L,rr=S.top().h;
ans2=ans1;
ans1=t;
}
else
{
if(t>=ans2)
ans2=t;
}
S.pop();
}
}
pr("%d\n",maxx(ans2,maxx((ll-)*rr,(rr-)*ll)));
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

最新文章

  1. 安卓Socket连接实现连接实现发送接收数据,openwrt wifi转串口连接单片机实现控制
  2. Log4j配置详解(转)
  3. 3-2-1-0-GO
  4. addsubview跟insertsubview的区别
  5. Keepalived安装及初步使用
  6. 织梦dedecms中html和xml格式的网站地图sitemap制作方法
  7. TCP服务器:多进程
  8. linux下串口的阻塞和非阻塞操作
  9. 发送Email并添加附件
  10. libevent在windows下使用步骤详解
  11. Invalid bound statement (not found): com.shizongger.chapter2.mapper.UserMapper.insertUser 解决方案
  12. Hive简单编程实践-词频统计
  13. BUG关闭原因
  14. C# 调用C++的dll 那些事
  15. Nginx系列二:(Nginx Rewrite 规则、Nginx 防盗链、Nginx 动静分离、Nginx+keepalived 实现高可用)
  16. 实验long raw 和 blob两种数据类型遇到dblink的表现
  17. FileMaker Server连接SQL Server测试
  18. SpringMVC高级参数绑定(数组和List)
  19. Linux中的yum是什么?如何配置?如何使用?
  20. 微软发布TFS 2018!

热门文章

  1. Windows上redis下载与安装
  2. luogu4212
  3. POJ 3694 Network ——(桥 + LCA)
  4. Oracle For Linux
  5. linux安装mysql可视化界面
  6. leetcode题目2.两数相加(中等)
  7. ajax 415
  8. Async Task Types in C#
  9. python3.*之列表常用操作
  10. ZOJ - 1586 QS Network (Prim)