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矩阵,问有多少个极大矩阵. 分析 对于悬线法来说,其过程就是枚举极大矩阵的过程,那如何计数呢?对于一个点来说,若其左右边界包含了上一个点的悬 ...
随机推荐
- 深入理解linux i节点(inode)
转载自:https://blog.csdn.net/vsooda/article/details/9216245 linux中,文件查找不是通过文件名称来查找的.实际上是通过i节点来实现文件的查找定位 ...
- SQL练习题(一)
目录 题目一:交换性别(简单) 实现思路 提交代码 题目二:连续出现的数字(中等) 实现思路 方式一 方式二 提交代码 方式一 方式二 题目三:换座位(中等) 实现思路 方式一 方式二 提交代码 方式 ...
- C# 调用R语言
在.net项目中需要调用Matlab生成的DLL,但是在调用过程中报错,截图如下: 在网上搜索一下资料,看到该博客:https://cn.mathworks.com/matlabcentral/new ...
- 生成TFRecord文件完整代码实例
import os import json def get_annotation_dict(input_folder_path, word2number_dict): label_dict = {} ...
- dp - 递推
C. Multiplicity time limit per test 3 seconds memory limit per test 256 megabytes input standard inp ...
- 关于neo4j初入门(3)
这一章主要是函数的部分 UPPER 它需要一个字符串作为输入并转换为大写字母. UPPER (<input-string>)<input-string>可以是来自Neo4J数据 ...
- python3三元运算
条件:简单的条件判断语句并且有返回值 作用:简化代码和装X 格式:为True执行的语句 if 判断条件 else 为False执行的语句 例子 def f(a, b): ""&qu ...
- python 找到项目使用的所有组件和版本
1.下载模块 pip3 install -i https://pypi.douban.com/simple pipreqs 2.生成文件 pipreqs ./ --encoding=utf-8
- Java对接微信公众号模板消息推送
内容有点多,请耐心! 最近公司的有这个业务需求,又很凑巧让我来完成: 首先想要对接,先要一个公众号,再就是开发文档了:https://developers.weixin.qq.com/doc/offi ...
- Bootstrap File Input 的使用
由于工作需要使用Bootstrap的FileInput插件,在此分享下插件的使用方法 直接上代码 fileinput.html <!DOCTYPE html> <html> & ...