All-one Matrices
单调栈
最大全一矩阵计数

#include<bits/stdc++.h>
#define maxn 3005
using namespace std;
#define P pair<int,int>
int n,m,ans,H[maxn][maxn],pre[maxn][maxn];
stack<P>st;
int a[maxn][maxn];
char c[maxn];//[maxn];
int main()
{
scanf("%d%d",&n,&m);
for(int i=; i<=n; i++)
{
scanf("%s",c+);
for(int j=; j<=m; j++) a[i][j]=c[j]-'';
}
for(int i=; i<=n; i++)
{
// tp=0;
for(int j=; j<=m; j++)
{
H[i][j]=((a[i][j])?H[i-][j]+:);
pre[i][j]=pre[i][j-]+(a[i][j]);
//cout<<pre[i][j]<<' ';
}
pre[i][m+]=pre[i][m];
//cout<<endl;
}
int x;
for(int i=;i<=n;i++){
while(!st.empty())st.pop();
for(int j=;j<=m+;j++){
x=j;
while(!st.empty()&&st.top().first>H[i][j]){
if(i==n||(pre[i+][j-]-pre[i+][st.top().second-])<(j-st.top().second)){
ans++;
}
x=st.top().second;
st.pop();
}
if((st.empty()||H[i][j]>st.top().first))
{ st.push(P(H[i][j],x));///以Hij为高的矩形最长能向左延伸到x
}
}
}
printf("%d",ans);
}
第二大全一矩阵,类似,单调栈,维护第二大
#include<bits/stdc++.h>
#define maxn 1005
using namespace std;
#define P pair<int,int>
int n,m,ans,H[maxn][maxn],pre[maxn][maxn];
stack<P>st;
int a[maxn][maxn];
char c[maxn];//[maxn];
int main()
{
scanf("%d%d",&n,&m);
for(int i=; i<=n; i++)
{
scanf("%s",c+);
for(int j=; j<=m; j++) a[i][j]=c[j]-'';
}
for(int i=; i<=n; i++)
{
// tp=0;
for(int j=; j<=m; j++)
{
H[i][j]=((a[i][j])?H[i-][j]+:);
pre[i][j]=pre[i][j-]+(a[i][j]);
// cout<<H[i][j]<<' ';
}
pre[i][m+]=pre[i][m];
//cout<<endl;
}
int x;
int ma1=,ma2=;
for(int i=; i<=n; i++)
{
while(!st.empty())st.pop();
for(int j=; j<=m+; j++)
{
x=j;
while(!st.empty()&&st.top().first>H[i][j])
{
if(i==n||(pre[i+][j-]-pre[i+][st.top().second-])<(j-st.top().second))
{
int a=j-st.top().second;
int b=st.top().first;
//cout<<i<<' '<<j<<endl; if(a*b>=ma1)
{
ma2=max(max(ma1,max(a*(b-),(a-)*b)),ma2);
ma1=a*b;
}
else
{
ma2=max(ma2,a*b);
}
//ans++;
}
x=st.top().second;
st.pop();
}
if(H[i][j]&&(st.empty()||H[i][j]>st.top().first))
{
st.push(P(H[i][j],x));
}
}
}
printf("%d\n",ma2);
}
All-one Matrices的更多相关文章
- 三对角矩阵(Tridiagonal Matrices)的求法:Thomas Algorithm(TDMA)
转载http://www.cnblogs.com/xpvincent/archive/2013/01/25/2877411.html 做三次样条曲线时,需要解三对角矩阵(Tridiagonal Mat ...
- 九度OnlineJudge之1001:A+B for Matrices
题目描述: This time, you are supposed to find A+B where A and B are two matrices, and then count the num ...
- Matrices and Vectors
Matrices and Vectors Matrices are 2-dimensional arrays: A vector is a matrix with one column and man ...
- Recovering Low-Rank Matrices From Few Coefficients In Any Basis
目录 引 主要结果 定理2,3 定理4 直观解释 Recovering Low-Rank Matrices From Few Coefficients In Any Basis-David Gross ...
- FAST LOW-RANK APPROXIMATION FOR COVARIANCE MATRICES
目录 Nystorm method 低秩逼近 矩阵乘法的逼近 Belabbas M A, Wolfe P J. Fast Low-Rank Approximation for Covariance M ...
- FAST MONTE CARLO ALGORITHMS FOR MATRICES II (快速的矩阵分解策略)
目录 问题 算法 LINEARTIMESVD 算法 CONSTANTTIMESVD 算法 理论 算法1的理论 算法2 的理论 代码 Drineas P, Kannan R, Mahoney M W, ...
- Codeforces Round #546 (Div. 2) C. Nastya Is Transposing Matrices
C. Nastya Is Transposing Matrices time limit per test 1 second memory limit per test 256 megabytes i ...
- 题目1001:A+B for Matrices
题目1001:A+B for Matrices 时间限制:1 秒内存限制:32 兆 题目描述: This time, you are supposed to find A+B where A and ...
- 九度oj 1001 A+B for Matrices 2011年浙江大学计算机及软件工程研究生机试真题
题目1001:A+B for Matrices 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:15235 解决:6172 题目描述: This time, you are supposed ...
- Diag:Diagonal matrices and diagonals of a matrix
Diag:Diagonal matrices and diagonals of a matrix Syntax X = diag(v,k) X = diag(v) v = diag(X,k) v = ...
随机推荐
- Oracle 查看一个数据库实例下面所有的表大小
1. 因为 oracle有一些 lob字段 在user_extents 里面取出来的结果不是表名, 所以需要与user_lobs 表做关联查询才可以 本来想通过 关联查询来实现, 发现字表查询更简单 ...
- 万万没想到,Spring Boot 竟然这么耗内存!
Spring Boot总体来说,搭建还是比较容易的,特别是Spring Cloud全家桶,简称亲民微服务. 但在发展趋势中,容器化技术已经成熟,面对巨耗内存的Spring Boot,小公司表示用不起. ...
- Highways POJ-1751 最小生成树 Prim算法
Highways POJ-1751 最小生成树 Prim算法 题意 有一个N个城市M条路的无向图,给你N个城市的坐标,然后现在该无向图已经有M条边了,问你还需要添加总长为多少的边能使得该无向图连通.输 ...
- [LeetCode] 164. 最大间距
题目链接 : https://leetcode-cn.com/problems/maximum-gap/ 题目描述: 给定一个无序的数组,找出数组在排序之后,相邻元素之间最大的差值. 如果数组元素个数 ...
- wordpress开发的一些积累
wordpress 攒知识点 记录开发 wordpress 的一些技能点,以备不时之需 短代码 Shortcode 虽然很多插件都是提供,直接在代码中插入类似[Shortcode] 便可以生效,但是很 ...
- CTS2018+1没去记&APIO2018+1游记
bgm Tips:想知道为什么标题不是2019吗,请看评论区 Day -2 md上午才写一道题qwq 机房里一堆dalao都回家收东西去北京了qwq,我菜死了,cts都去不了QAQ 下午晚上也才肝了两 ...
- 声明对象的方式/构造函数/原型/this指向
函数的发展历程(声明函数的方式): 1.通过Object构造函数或字面量的方式创建单个对象 var obj = new Object; obj.name="新华"; o ...
- 梯度下降算法(Gradient descent)GD
1.我们之前已经定义了代价函数J,可以将代价函数J最小化的方法,梯度下降是最常用的算法,它不仅仅用在线性回归上,还被应用在机器学习的众多领域中,在后续的课程中,我们将使用梯度下降算法最小化其他函数,而 ...
- iOS开发之详解剪贴板
关于UIMenuController的用法例子 今天终于搞明白了UIMenuController显示的相关内容,把源代码分享给大家! 要正常显示菜单,必须做到以下几点:1. -(BOOL)canBec ...
- lldb调试命令
XCode4.0以后,编译器换成了LLVM 编译器 2.0 与以前相比,更加强大:1.LLVM 编译器是下一带开源的编译技术.完全支持C, Objective-C, 和 C++.2.LLVM 速度比 ...