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. python 并发编程 多进程 队列

    队列介绍 进程彼此之间互相隔离,要实现进程间通信(IPC),multiprocessing模块支持两种形式:队列和管道,这两种方式都是使用消息传递的 创建队列的类(底层就是以管道和锁定的方式实现) 制 ...

  2. [转帖]又一国产x86处理器可大规模上市:Intel至强核心 安全监测管控

    又一国产x86处理器可大规模上市:Intel至强核心 安全监测管控 https://www.cnbeta.com/articles/tech/850525.htm 不知道是不是有一起汉芯事件 国产CP ...

  3. Mybatis—动态sql拼接问题

    背景:使用Mybatis的最近半年,经常发现一些小坑,现在总结回顾下,记个小本本,不让它再来欺负我! 百度了许久,才留心到官网文档,比我的全,我很菜的! *************<if> ...

  4. java面向对象详细全面介绍

    一.面向对象 1.面向过程与面向对象 POP与OOP都是一种思想,面向对象是相对于面向过程而言的.面向过程,强调的是功能行为,以函数为最小单位,考虑怎么做.面向对象,将功能封装进对象,强调具备了功能的 ...

  5. 《剑指offer》面试题26 复杂链表的复制 Java版

    (定义一个新的数据结构,每个节点除了具有普通链表的next域外,还有一个额外的引用指向任意节点.我们要对由该特殊数据结构形成的链表进行复制.) 我的方法:也就是克隆一个这种特殊链表,很快想到先不考虑原 ...

  6. 洛谷 P5662 纪念品 & [NOIP2019普及组] (dp,完全背包)

    传送门 解题思路 本题首先要明白,在每一天时,最优策略是先进行操作2(卖),再进行操作1(买),才能是利益最大化. 本题很显然当只有两天时,是一个完全背包,就是把当日价钱当做体积,把明日价格和今日价格 ...

  7. Linux :环境变量设置和本地变量加载

    bash: 全局变量: /etc/profile,  /etc/profile.d/*,  /etc/bashrc 个人变量: ~/.bash_profile,   ~/.bashrc bash运行方 ...

  8. Text Autosizer&&解决移动端网页文本字体怪异增大问题

    在做移动端页面时,有时你设置了字体大小,有的部分即使设置了行内样式也不生效,而有些显示正常,这个特性就是Text Autosizer在搞鬼. 以下是解决方案: ①给元素设置 -webkit-text- ...

  9. Redis---键的过期时间及数据淘汰策略

    5.键的过期时间   Redis可以为每个键设置过期时间,当键过期时,会自动删除该键.   对于散列表这种容器,只能为整个键设置过期时间(整个散列表),而不能为键里面的单个元素设置过期时间. 6.数据 ...

  10. SpringBoot_03mybatisPlus

    注意: mybatisPlus默认加载resources下的mapper文件夹下的xml文件 默认将数据库表的字段用驼峰标识转换成实体类的属性 官方网站: https://mp.baomidou.co ...