2019牛客暑期多校训练营(第二场)H Second Large Rectangle
题目链接:https://ac.nowcoder.com/acm/contest/882/H
题目描述
Given a N×M
binary matrix. Please output the size of second large rectangle containing all "1".
Containing all "1" means that the entries of the rectangle are all "1".
A rectangle can be defined as four integers x1,y1,x2,y2
where 1≤x1≤x2≤N and 1≤y1≤y2≤M. Then, the rectangle is composed of all the cell (x, y) where x1≤x≤x2 and y1≤y≤y2. If all of the cell in the rectangle is "1"
, this is a valid rectangle.
Please find out the size of the second largest rectangle, two rectangles are different if exists a cell belonged to one of them but not belonged to the other.
输入描述:
The first line of input contains two space-separated integers N and M.
Following N lines each contains M characters cij
.1≤N,M≤1000
N×M≥2
cij∈"01"
输出描述:
Output one line containing an integer representing the answer. If there are less than 2 rectangles containning all "1"
, output "0"
.
示例1
输入
复制
1 2 01
输出
复制
0
示例2
输入
复制
1 3 101
输出
复制
1
题面大意:
给出一个由0和1组成的一个矩阵,求出出这个矩阵中全部由1组成的第二大的子矩阵
需要使用单调栈
对矩阵进行处理, 转化成一个直方图,然后套用单调栈即可
代码:
#include<iostream>
#include<stdio.h>
#include<stack>
using namespace std;int max1=0,max2=0;
int a[1010][1010];
char b[1010];void check(int n){if(n>max1){int t=max1;max1=n;max2=t;}else if(n>max2){max2=n;}
}void Area(int x,int y){check(x*y);check((x-1)*y);check(x*(y-1));
}int main(){int n,m;cin>>n>>m;for(int i=1;i<=n;i++){cin>>b;for(int j=1;j<=m;j++){a[i][j]=b[j-1]-'0';if(a[i][j]==1){a[i][j]+=a[i-1][j];}}}for(int i=1;i<=n;i++){a[i][0]=-2;a[i][m+1]=-1;stack<int> q;q.push(0);for(int j=1;j<=m+1;j++){while(a[i][q.top()]>a[i][j]){int index=q.top();q.pop();Area(j-q.top()-1,a[i][index]);}q.push(j);}}cout<<max2<<endl;
}
2019牛客暑期多校训练营(第二场)H Second Large Rectangle相关推荐
- [题解] 2019牛客暑期多校第三场H题 Magic Line
题目链接:https://ac.nowcoder.com/acm/contest/883/H 题意:二维平面上有n个不同的点,构造一条直线把平面分成两个点数相同的部分. 题解:对这n个点以x为第一关键 ...
- 2019牛客暑期多校训练营(第三场)H.Magic Line
2019牛客暑期多校训练营(第三场)H.Magic Line 题目链接 题目描述 There are always some problems that seem simple but is diff ...
- 2019牛客暑期多校训练营(第五场)C generator 2 (BSGS)
2019牛客暑期多校训练营(第五场)C generator 2 思路 x0=x0x_0 = x_0x0=x0 x1=a∗x0∗bx_1 = a * x_0 * bx1=a∗x0∗b x2=a∗ ...
- 2019牛客暑期多校训练营(第四场)----E- triples II
首先发出题目链接: 链接:https://ac.nowcoder.com/acm/contest/884/E 来源:牛客网 涉及:位运算,容斥定义,dp 点击这里回到2019牛客暑期多校训练营解题-目 ...
- 【2019牛客暑期多校训练营(第二场) - H】Second Large Rectangle(单调栈,全1子矩阵变形)
题干: 链接:https://ac.nowcoder.com/acm/contest/882/H 来源:牛客网 题目描述 Given a N×MN \times MN×M binary matrix. ...
- 【2019牛客暑期多校训练营(第二场)- F】Partition problem(dfs,均摊时间优化)
题干: 链接:https://ac.nowcoder.com/acm/contest/882/F 来源:牛客网 Given 2N people, you need to assign each of ...
- 暑假N天乐【比赛篇】 —— 2019牛客暑期多校训练营(第二场)
最近几天都没写博客,真是没什么时间写了,专题卡着,一周四场比赛,场场爆零,补题都补傻了.第一场还差两题可能今天补掉吧,昨天的杭电也是完全没动,感觉...很烦 第二场牛客断断续续也是补了几天...大概一 ...
- 【2019牛客暑期多校训练营(第二场)- E】MAZE(线段树优化dp,dp转矩阵乘法,线段树维护矩阵乘法)
题干: 链接:https://ac.nowcoder.com/acm/contest/882/E?&headNav=acm 来源:牛客网 Given a maze with N rows an ...
- 【2019牛客暑期多校训练营(第二场) - D】Kth Minimum Clique(bfs,tricks)
题干: 链接:https://ac.nowcoder.com/acm/contest/882/D 来源:牛客网 Given a vertex-weighted graph with N vertice ...
最新文章
- word怎么根据点画曲线_圆锥曲线联解公式
- How to make Windows Form app truly Full Screen (and to hide Taskbar) in C#? 转
- SparkSQL之DataFrame案例
- CodeForces - 560E Gerald and Giant Chess(组合数学+dp)
- 在电路设计中,这7个接口类型太重要了,我难道不该学学么!
- html请求接口_软件测试学习教程——LoadRunner实现接口测试
- Redis(1)---五种数据结构
- springsecurity 认证之密码模式
- 【JPA】字段访问、属性访问及混合访问
- 微信团队分享:iOS版微信的高性能通用key-value组件技术实践
- 【javascript】ajax 基础(转)
- [转]FCKeditor在ASP配置环境中的使用
- rgb转hsi matlab,Matlab实现HSI与RGB转换 | 学步园
- prometheus + grafana 对 springboot 项目进行监控
- 一天掌握数据结构与算法,建议收藏
- 论文阅读:预训练模型:过去,现在和未来 Pre-Trained Models: Past, Present and Future(上)
- 凯悦酒店集团完成收购Apple Leisure Group;复星旅文在第四届进博会上完成近10项国际合作签约 | 全球旅报...
- 详解Shell脚本:sed命令工具 ,awk命令工具
- 18、弱电工程综合布线系统常用的线材及设备图文资料
- No manual entry for xxx 错误的解决方案