第二大矩阵面积--(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 题目传送门 解题思路 先求出每个点上的高,再利用单调栈分别求出每个点左右两边第一个高小于自己的位置,从而而得出最后一个大于等于自己的位置,进而求出自己的位 ...
随机推荐
- canvas小实验
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- css引入第三方字体
上面图片时将字体文件放入到fonts文件夹内, 里面有一个fonts.css文件,将字体文件声明好, 然后像下面图片一样,在另外一个css内@import引入,(当然,也可以直接将声明和引用放在一个c ...
- python用BeautifulSoup解析源码时,去除空格及换行符
一.去除空格 strip() " xyz ".strip() # returns "xyz" " xyz ".lstrip() # ...
- ngx_http_auth_request_module 第三方认证
shell > vim /usr/local/nginx-1.10.2/conf/vhost/auth.conf # 这是第三方认证服务器,认证逻辑使用的 PHP 代码 server { lis ...
- linux安装mysql以及修改密码和重启mysql等相关命令
Linux/UNIX 上安装 MySQL Linux平台上推荐使用RPM包来安装Mysql,MySQL AB提供了以下RPM包的下载地址: MySQL - MySQL服务器.你需要该选项,除非你只想连 ...
- window 下要运行php,需要编辑php环境变量
参考:https://blog.csdn.net/zhezhebie/article/details/72765262
- thinkpad T480安装WIN7
本文转载自http://www.dnxtc.net/zixun/zhuangjijiaocheng/2018-12-01/3256.html 防止忘记 特别把资源集中一下 新买的笔记本预装的WIN10 ...
- Movidius的深度学习入门
1.Ubuntu虚拟机上安装NC SDK cd /home/shine/Downloads/ mkdir NC_SDK git clone https://github.com/movidius/nc ...
- springboot ---> spring ioc 注册流程 源码解析 this.prepareContext 部分
现在都是在springboot 中 集成 spirng,那我们就从springboot 开始. 一:springboot 启动main 函数 public static void main(Strin ...
- javascript之DOM四位的验证码简单实现
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...