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);
}

Second Large Rectangle

第二大全一矩阵,类似,单调栈,维护第二大

#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的更多相关文章

  1. 三对角矩阵(Tridiagonal Matrices)的求法:Thomas Algorithm(TDMA)

    转载http://www.cnblogs.com/xpvincent/archive/2013/01/25/2877411.html 做三次样条曲线时,需要解三对角矩阵(Tridiagonal Mat ...

  2. 九度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 ...

  3. Matrices and Vectors

    Matrices and Vectors Matrices are 2-dimensional arrays: A vector is a matrix with one column and man ...

  4. 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 ...

  5. FAST LOW-RANK APPROXIMATION FOR COVARIANCE MATRICES

    目录 Nystorm method 低秩逼近 矩阵乘法的逼近 Belabbas M A, Wolfe P J. Fast Low-Rank Approximation for Covariance M ...

  6. FAST MONTE CARLO ALGORITHMS FOR MATRICES II (快速的矩阵分解策略)

    目录 问题 算法 LINEARTIMESVD 算法 CONSTANTTIMESVD 算法 理论 算法1的理论 算法2 的理论 代码 Drineas P, Kannan R, Mahoney M W, ...

  7. 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 ...

  8. 题目1001:A+B for Matrices

    题目1001:A+B for Matrices 时间限制:1 秒内存限制:32 兆 题目描述: This time, you are supposed to find A+B where A and  ...

  9. 九度oj 1001 A+B for Matrices 2011年浙江大学计算机及软件工程研究生机试真题

    题目1001:A+B for Matrices 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:15235 解决:6172 题目描述: This time, you are supposed ...

  10. 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 =  ...

随机推荐

  1. Fabric CA/数字证书管理

    MSP(Membership Service Provider)成员管理服务提供商 名词: 1.CSR(Cerificate Signing Request):证书签署请求文件 CSR里包含申请者的 ...

  2. linux 通配符与正则表达式

    linux通配符和三剑客(grep.awk.sed)正则表达式是不一样的 通配符一般用户命令行bash环境,而linux正则表达式用于awk.grep.sed

  3. 虚拟机上首次安装Ubuntu后 root密码设置

    虚拟机下安装ubuntu后root密码设置 问题描述: 在虚拟机下安装了ubuntu中要输入用户名,一般情况下大家都会输入一个自己的网名或绰号之类的,密码也在这时设置过了. 但是当安装成功之后,使用命 ...

  4. 为何单片机程序不用加载到RAM

    一. STM32程序构成 1.1. STM32的存储空间 1.1.1. RAM 1.1.1.1 单片机的RAM是SRAM. 1.1.1.2. SRAM特点 a.优点,速度快,不必配合内存刷新电路,可提 ...

  5. idea 代码部分格式化

    效果: 处理Idea使用ctrl+alt+L进行代码格式化时部分代码可以被忽略,不执行格式化功能(webstorm,phpstorm同理) 原因: 有时希望自己写的一些代码不被格式化,或者发现格式化后 ...

  6. OI那些事——AFO

    \(OI\)那些事--\(AFO\) 世界上从此少了一个\(Oier\)也不会有人知道,也许只有某个人在某年某月某日翻到了Eternal 风度的博客才会发现:哇,这哥们怎么\(Noip\)就退役了 两 ...

  7. 4-2如何判断字符串a是否以字符串b开头或结尾

    1.相关介绍 1.1修改文件权限和查看文件权限 在windows平台实验时 os.chmod()无法将文件权限修改为可执行,暂不深究如何实现.在linux平台进行测试. (1)创建三个文件 pytho ...

  8. Lucene整理--中文分词

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/hai_cheng001/article/details/37511379 看lucene主页(htt ...

  9. 绝对定位left:50% 隐式设置了宽度

    绝对定位left:50% 隐式设置了宽度 不定宽高的盒子如何在父盒子中垂直居中,我们常做的一种方式便是 left: 50%; top: 50%; transform: translate(-50%, ...

  10. git init error:Malformed value for push.default: simple

    git init error:Malformed value for push.default: simple 1.git config --global push.default matching