题意:

求第二大子矩形

思路:

设最大子矩形x*y,第二大子矩形一定在一下情况中

(x-1)*y

x*(y-1)

其他最大子矩形候选者

注意去重手法

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
//#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1 using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 1e4+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
//const db pi = acos(-1.0); int a[][];
int l[][];
int r[][];
multiset<int>ans;
int h[][];
int lft[][];
int rt[][];
int n, m; int main(){
scanf("%d %d" ,&n, &m);
for(int i = ; i <= n; i++){
for(int j = ; j <= m; j++){
scanf("%1d",&a[i][j]);
}
}
for(int i = ; i <= n; i++){
int tmp = ;
for(int j = ; j <= m; j++){
if(a[i][j]==)tmp=j;
lft[i][j]=tmp;
}
tmp=m+;
for(int j = m; j >= ; j--){
if(a[i][j]==)tmp=j;
rt[i][j]=tmp;
}
}
PI mx=make_pair(-,-);
int up = -;
int mxs = ;
for(int i = ; i <= n; i++){
for(int j = ; j <= m; j++){
if(i==||a[i-][j]==)h[i][j]=;
else h[i][j]=h[i-][j]+;
if(h[i][j]==){
l[i][j] = lft[i][j];
r[i][j] = rt[i][j];
}
else{
l[i][j] = max(l[i-][j],lft[i][j]);
r[i][j] = min(r[i-][j], rt[i][j]);
}
if(a[i][j]==)continue;
int res = (r[i][j]-l[i][j]-)*h[i][j];
if(res>mxs){
mxs=res;
mx = make_pair(i,j);up=i-h[i][j]+;
}
}
}
int ans = max((r[mx.fst][mx.sc]-l[mx.fst][mx.sc]-)*(h[mx.fst][mx.sc]-),(r[mx.fst][mx.sc]-l[mx.fst][mx.sc]-)*h[mx.fst][mx.sc]);
//printf("%d\n",ans);
for(int i = ; i <= n; i++){
for(int j = ; j <= m; j++){
if(l[i][j]==l[mx.fst][mx.sc]&&r[i][j]==r[mx.fst][mx.sc]&&i-h[i][j]+==up)continue;
int sum = (r[i][j]-l[i][j]-)*h[i][j];
if(sum>ans){
ans=sum;
}
}
}
printf("%d",ans);
return ;
}
/*
1 2
11
3 3
110
111
011
3 3
111
011
011
1 4
1011
3 4
1101
0111
1111
7 8
11110000
11110000
00000111
01110111
01110111
01110000
00000000
4 4
1111
1111
1111
1111
3 3
111
010
010
2 6
010011
001111
3 3
011
111
111
*/
05-21 23:33