题目描述 Description
有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地。
这片土地被分成N*M个格子,每个格子里写着’R’或者’F’,R代表这块土地被赐予了rainbow,F代表这块土地被赐予了freda。
现在freda要在这里卖萌。。。它要找一块矩形土地,要求这片土地都标着’F’并且面积最大。
但是rainbow和freda的OI水平都弱爆了,找不出这块土地,而蓝兔也想看freda卖萌(她显然是不会编程的……),所以它们决定,如果你找到的土地面积为S,它们每人给你S两银子。
【题目分析】
单调栈,垃圾oj抄tyvj
【代码】
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n,m,ans=0;
int a[1001][1001];
int h[1001][1001];
char opt[5];
struct node{int hi,wi;}sta[2001];
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
{
scanf("%s",opt);
if (opt[0]=='F') a[i][j]=1;
}
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
if (a[i][j]) h[i][j]=h[i-1][j]+1;
for (int z=1;z<=n;++z)
{
int top=0;
for (int i=1;i<=m+1;++i)
{
while (top&&h[z][i]<sta[top].hi)
{
if (!(top-1))
{
ans=max(sta[top].hi*sta[top].wi,ans);
sta[top].hi=h[z][i];
}
else if (sta[top-1].hi<h[z][i])
{
ans=max(ans,sta[top].hi*sta[top].wi);
sta[top].hi=h[z][i];
}
else if (sta[top-1].hi>=h[z][i])
{
ans=max(ans,sta[top].hi*sta[top].wi);
sta[top-1].wi+=sta[top].wi;
top--;
}
}
if (h[z][i]==sta[top].hi) sta[top].wi++;
else
{
top++;
sta[top].hi=h[z][i];
sta[top].wi=1;
}
}
}
printf("%d\n",ans*3);
}