题意:

求第二大子矩形

思路:

设最大子矩形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
*/

2019牛客多校2 H Second Large Rectangle(悬线法)的更多相关文章

  1. 2019牛客多校第二场H-Second Large Rectangle

    Second Large Rectangle 题目传送门 解题思路 先求出每个点上的高,再利用单调栈分别求出每个点左右两边第一个高小于自己的位置,从而而得出最后一个大于等于自己的位置,进而求出自己的位 ...

  2. 2019牛客多校一 H. XOR (线性基)

    大意: 给定序列, 求所有异或和为$0$的子序列大小之和. 先求出线性基, 假设大小为$r$. 对于一个数$x$, 假设它不在线性基内, 那么贡献为$2^{n-r-1}$ 因为它与其余不在线性基内数的 ...

  3. 2019牛客多校八 H. How Many Schemes (AC自动机,树链剖分)

    大意: 给定树, 每条边有一个字符集合, 给定$m$个模式串, $q$个询问$(u,v)$, 对于路径$(u,v)$中的所有边, 每条边从对应字符集合中取一个字符, 得到一个串$s$, 求$s$至少包 ...

  4. 第二大矩阵面积--(stack)牛客多校第二场-- Second Large Rectangle

    题意: 给你一幅图,问你第二大矩形面积是多少. 思路: 直接一行行跑stack求最大矩阵面积的经典算法,不断更新第二大矩形面积,注意第二大矩形可能在第一大矩形里面. #define IOS ios_b ...

  5. 2019牛客多校第八场 F题 Flowers 计算几何+线段树

    2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...

  6. 2019牛客多校第一场 I Points Division(动态规划+线段树)

    2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...

  7. 2019牛客多校第二场 A Eddy Walker(概率推公式)

    2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...

  8. 2019牛客多校 Round4

    Solved:3 Rank:331 B xor 题意:5e4个集合 每个集合最多32个数 5e4个询问 询问l到r个集合是不是都有一个子集的xor和等于x 题解:在牛客多校第一场学了线性基 然后这个题 ...

  9. 2019牛客多校第八场A All-one Matrices 悬线法,单调栈待补

    All-one Matrices 题意 对于一个n,m的01矩阵,问有多少个极大矩阵. 分析 对于悬线法来说,其过程就是枚举极大矩阵的过程,那如何计数呢?对于一个点来说,若其左右边界包含了上一个点的悬 ...

随机推荐

  1. java数据结构之常用排序算法

    冒泡排序 private void maopao(int arr[]) { for (int i = 0; i < arr.length; i++) { for (int j = 0; j &l ...

  2. 24.python中xlwt模块用法详解

    1.创建并保存一个excel 创建一个工作簿,设置编码格式为“utf-8”,默认格式是ASCII,为了方便写入中文,一般都要设置成UTF-8 import xlwt wb = xlwt.Workboo ...

  3. 一起来立Flag吧!超炫的数据图表分析 2020 年 Java 技术趋势

    引言 2020 来了,第一批 00 后已经 20 岁了,95 后也到了晚婚的年龄,员外的头发也越来越少了,新的一年大家有立下了哪些 Flag ?小伙伴们别急着立 Flag,让员外帮你分析一下哪些技术正 ...

  4. 如何在oracle中缩小临时表空间?ORA-01652无法在表空间中扩展temp

    查询临时表空间有多大: SQL> SELECT tablespace_name, file_name, bytes FROM dba_temp_files WHERE tablespace_na ...

  5. C语言之函数用法总结

    C语言函数概述: 构成C语言程序的基本模块,模块化编程的最小单位. 函数调用的基本方式: 函数调用时的数据传递: 函数调用的过程: 函数原型与函数定义的区别: 函数封装: 1.外界对函数的影响仅限于入 ...

  6. 原生javascript 基础动画函数封装(二)

    <!DOCTYPE html> <html> <head> <title></title> <style type="tex ...

  7. 更加清晰的TFRecord格式数据生成及读取

    TFRecords 格式数据文件处理流程 TFRecords 文件包含了 tf.train.Example 协议缓冲区(protocol buffer),协议缓冲区包含了特征 Features.Ten ...

  8. Airbnb如何应用AARRR策略成为全球第一民宿平台

    案例背景 基于房东和租客的痛点构建短租平台,但困于缓慢增长 2007年,住在美国旧金山的两位设计师——BrianChesky与Joe Gebbia正在为他们付不起房租而困扰.为了赚点外块,他们计划将阁 ...

  9. .net 解析嵌套JSON

    JSON格式文件如下:我们是要取出msgJsoncontent里面GeneralReportInfo下serviceData中的totalUseValue数据 { ", "mess ...

  10. python 线程事件

    与进程的事件相似 # 事件,模拟连接数据库 import time from threading import Event, Thread def wait(e): while 1: e.wait(1 ...