第二大矩阵面积--(stack)牛客多校第二场-- Second Large Rectangle
题意:
给你一幅图,问你第二大矩形面积是多少。
思路:
直接一行行跑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;
}
第二大矩阵面积--(stack)牛客多校第二场-- Second Large Rectangle的更多相关文章
- 2019牛客多校2 H Second Large Rectangle(悬线法)
题意: 求第二大子矩形 思路: 设最大子矩形x*y,第二大子矩形一定在一下情况中 (x-1)*y x*(y-1) 其他最大子矩形候选者 注意去重手法 代码: #include<iostream& ...
- 2019牛客多校第二场 A Eddy Walker(概率推公式)
2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...
- 2019牛客多校第一场 I Points Division(动态规划+线段树)
2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...
- 牛客多校第一场 B Inergratiion
牛客多校第一场 B Inergratiion 传送门:https://ac.nowcoder.com/acm/contest/881/B 题意: 给你一个 [求值为多少 题解: 根据线代的知识 我们可 ...
- 2019年牛客多校第一场B题Integration 数学
2019年牛客多校第一场B题 Integration 题意 给出一个公式,求值 思路 明显的化简公式题,公式是分母连乘形式,这个时候要想到拆分,那如何拆分母呢,自然是裂项,此时有很多项裂项,我们不妨从 ...
- 2019年牛客多校第二场 H题Second Large Rectangle
题目链接 传送门 题意 求在\(n\times m\)的\(01\)子矩阵中找出面积第二大的内部全是\(1\)的子矩阵的面积大小. 思路 处理出每个位置往左连续有多少个\(1\),然后对每一列跑单调栈 ...
- 2019 牛客多校第二场 H Second Large Rectangle
题目链接:https://ac.nowcoder.com/acm/contest/882/H 题目大意 给定一个 n * m 的 01 矩阵,求其中第二大的子矩阵,子矩阵元素必须全部为 1.输出其大小 ...
- 牛客多校第二场H Second Large Rectangle 单调栈or悬线法
Second Large Rectangle 题意 给出n*m的01矩阵,问由1组成的第二大的矩阵的大小是多少? 分析 单调栈(or 悬线法)入门题 单调栈 预处理出每一个点的最大高度,然后单调栈每一 ...
- 2019牛客多校第二场H-Second Large Rectangle
Second Large Rectangle 题目传送门 解题思路 先求出每个点上的高,再利用单调栈分别求出每个点左右两边第一个高小于自己的位置,从而而得出最后一个大于等于自己的位置,进而求出自己的位 ...
随机推荐
- zabbix服务端接收的数据类型,便于编写脚本向服务端提交数据
1.数据类型1:zabbix_agent执行脚本提交字典 UserParameter=tcp_port_listen,/usr/local/zabbix/share/script/get_game_p ...
- intellij idea http proxy config
# custom IntelliJ IDEA properties #http proxy -DproxySet=true -Dhttp.proxyHost=127.0.0.1 -Dhttp.prox ...
- 关于一次同余方程的一类解法(exgcd,CRT,exCRT)
1.解同余方程: 同余方程可以转化为不定方程,其实就是,这样的问题一般用拓展欧几里德算法求解. LL exgcd(LL a,LL b,LL &x,LL &y){ if(!b){ x=; ...
- Nginx 配置443 HTTPS
server { listen 443 ssl; server_name localhost; ssl on; ssl_certificate D://newlingshou//nginx-1.12. ...
- Python中异常和JSON读写数据
异常可以防止出现一些不友好的信息返回给用户,有助于提升程序的可用性,在java中通过try ... catch ... finally来处理异常,在Python中通过try ... except .. ...
- 取得远端相应Json并转化为Java对象(嵌套对象)二
工程下载链接:https://files.cnblogs.com/files/xiandedanteng/JsonParse20190929.rar 客户端: 如果从Restful Service取得 ...
- GitHub:Baidu
ylbtech-GitHub:Baidu 1.返回顶部 · duedge-recipes DuEdge百度边缘网络计算样例代码 edgeedge-computingduedge JavaScri ...
- js字符串常用函数
字符截取函数 1. array.slice(start, end) 第一个参数代表开始位置,第二个参数代表结束位置的下一个位置 start:规定从何处开始选取. 如果是负数,那么它规定从数组尾部开始算 ...
- pandas中的reset_index()
数据清洗时,会将带空值的行删除,此时DataFrame或Series类型的数据不再是连续的索引,可以使用reset_index()重置索引. import pandas as pd import nu ...
- 安卓之Android.mk编写
题记:编译环境可以参考https://www.cnblogs.com/ywjfx/p/9960817.html 不管是写C还是java,我想所有的程序员都经历过HelloWorld程序的编写,现在让我 ...