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 = ...
随机推荐
- Java第一周总结
通过两周的Java学习最深刻的体会就是Java好像要比C要简单一些. 然后这两周我学习到了很多东西,李老师第一次上课就给我们介绍了Java的发展历程,同时还有Java工具jdk的发展历程. Java语 ...
- debian 安装java
sudo apt-get update sudo apt-get install default-jre sudo apt-get install default-jdk
- GraphQL入门有这一篇就足够了
GraphQL入门有这一篇就足够了:https://blog.csdn.net/qq_41882147/article/details/82966783 版权声明:本文为博主原创文章,遵循 CC 4. ...
- C++中对象的构造顺序
1,C++ 中的类可以定义多个对象,那么对象构造顺序是怎样的? 1,很多的 bug 是由对象的构造顺序造成的,虽然它不难: 2,对象的构造往往和构造函数牵涉在一起,构造函数的函数体又可能由非常复杂的程 ...
- CDQ分治总结
\(CDQ\)分治小结 标签:知识点总结 阅读体验:https://zybuluo.com/Junlier/note/1326395 身为一个资深菜鸡 \(CDQ\)分治一开始学了一晚上,后来某一天又 ...
- easyui 前端分页及前端查询
1.静态分页核心方法 // 前端分页 -- 将datagrid的loadFilter属性设置为这个方法名即可 function partPurchasePagerFilter(data) { if ( ...
- FreeMarker三宗罪之优缺点
FreeMarker是Quake Wang推荐我使用的.刚学FreeMarker的时候,发现freemarker真的很棒!简单易用,功能强大.但是用它做了几个项目以后开始不爽了. 一宗罪:freema ...
- cookie,localStorage和sessionStorage
一.Cookie Cookie 是小甜饼的意思.cookie 非常小,它的大小限制为4KB左右.它的主要用途有保存登录信息,比如你登录某个网站市场可以看到“记住密码”,这通常就是通过在 Cookie ...
- 把excel中的数据导入到Oracle数据库中
从事工作以来,数据库一直使用oracle,却不知道excel导入oracle,今天看了一篇文章,分享给大家,希望对大家有用. https://jingyan.baidu.com/article/0f5 ...
- mv - 移动 (改名) 文件
摘要 mv [选项]... 源文件 目标文件 mv [选项]... 源文件... 目录 mv [选项]... --target-directory=DIRECTORY SOURCE... 描述 改“源 ...