2019牛客多校2 H Second Large Rectangle(悬线法)
题意:
求第二大子矩形
思路:
设最大子矩形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(悬线法)的更多相关文章
- 2019牛客多校第二场H-Second Large Rectangle
Second Large Rectangle 题目传送门 解题思路 先求出每个点上的高,再利用单调栈分别求出每个点左右两边第一个高小于自己的位置,从而而得出最后一个大于等于自己的位置,进而求出自己的位 ...
- 2019牛客多校一 H. XOR (线性基)
大意: 给定序列, 求所有异或和为$0$的子序列大小之和. 先求出线性基, 假设大小为$r$. 对于一个数$x$, 假设它不在线性基内, 那么贡献为$2^{n-r-1}$ 因为它与其余不在线性基内数的 ...
- 2019牛客多校八 H. How Many Schemes (AC自动机,树链剖分)
大意: 给定树, 每条边有一个字符集合, 给定$m$个模式串, $q$个询问$(u,v)$, 对于路径$(u,v)$中的所有边, 每条边从对应字符集合中取一个字符, 得到一个串$s$, 求$s$至少包 ...
- 第二大矩阵面积--(stack)牛客多校第二场-- Second Large Rectangle
题意: 给你一幅图,问你第二大矩形面积是多少. 思路: 直接一行行跑stack求最大矩阵面积的经典算法,不断更新第二大矩形面积,注意第二大矩形可能在第一大矩形里面. #define IOS ios_b ...
- 2019牛客多校第八场 F题 Flowers 计算几何+线段树
2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...
- 2019牛客多校第一场 I Points Division(动态规划+线段树)
2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...
- 2019牛客多校第二场 A Eddy Walker(概率推公式)
2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...
- 2019牛客多校 Round4
Solved:3 Rank:331 B xor 题意:5e4个集合 每个集合最多32个数 5e4个询问 询问l到r个集合是不是都有一个子集的xor和等于x 题解:在牛客多校第一场学了线性基 然后这个题 ...
- 2019牛客多校第八场A All-one Matrices 悬线法,单调栈待补
All-one Matrices 题意 对于一个n,m的01矩阵,问有多少个极大矩阵. 分析 对于悬线法来说,其过程就是枚举极大矩阵的过程,那如何计数呢?对于一个点来说,若其左右边界包含了上一个点的悬 ...
随机推荐
- 配置ca服务器和http,mail加密
一·CA介绍 certificate authority 数字证书授权中心 被通信双方信任的.独立的第三方机构 负责证书颁发.验证.撤销等管理 数字证书 经证书授权中心数字签名的包含公开密钥拥有者 ...
- HTTP请求中的GET-POST方式
目录 一.前言部分(概念) 二.对比 GET 与 POST 二者最大的差异 GET 与 POST 请求本质上并无区别 深层了解:POST 请求产生两个数据包? 三.两种请求方式如何灵活使用? 四.常见 ...
- Spring Cloud Stream消息驱动@SendTo和消息降级
参考程序员DD大佬的文章,自己新建demo学习学习,由于需要消息回执,看到了@SendTo这个注解能够实现,下面开始学习demo,新建两个项目cloud-stream-consumer消费端 和 cl ...
- Lincode刷题No.8
8.Rotate String lintcode 题解1: class Solution { public: /** * @param str: An array of char * @param o ...
- 小白学 Python 爬虫(38):爬虫框架 Scrapy 入门基础(六) Item Pipeline
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...
- AspectJ——预编译方式实现AOP
- 用Django自动生成表遇到问题
因为以前在数据库中已经生成过Django 叫App01下的表,所以无法生成,在数据库中执行这个命令 DELETE FROM django_migrations WHERE app='App01';然后 ...
- Java 项目热部署,节省构建时间的正确姿势
上周末,帮杨小邪(我的大学室友)远程调试项目.SpringBoot 构建,没有热部署,改一下就得重启相关模块.小小的 bug ,搞了我一个多小时,大部分时间都还在构建上(特么,下次得收钱才行).我跟他 ...
- 初识 ST 表
推荐博客 : https://blog.csdn.net/BerryKanry/article/details/70177006 ST表通常用于RMQ问题中,询问某个区间的最值这类问题中 ST表的核心 ...
- python爬虫——selenium+firefox使用代理
本文中的知识点: python selenium库安装 firefox geckodriver的下载与安装 selenium+firefox使用代理 进阶学习 搭建开发环境: selenium库 fi ...