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. OSPF与ACL 综合应用

    1.企业内网运行OSPF路由协议,区域规划如图所示:2.财务和研发所在的区域不受其他区域链路不稳定性影响:3.R1.R2.R3只允许被IT登录管理:4.YF和CW之间不能互通,但都可以与IT互通:5. ...

  2. 软技能-代码外的生存指南PDF下载

    编程只是我们职业生涯中的一部分,我们还需要更多的其他技能 链接:https://pan.baidu.com/s/1d7z_7NCEFT2lsSWO1n-OuA 提取码:zj32 链接失效请留言

  3. 银河麒麟v4.0.2 安装gscloud的简单过程

    1. 本来想用 tar包安装 redis 结果总是报错, 提示需要make test 但是我已经make test 了 所以还是使用 apt-get来安装. 2. 方式 apt-get update ...

  4. 2017沈阳区域赛Infinite Fraction Path(BFS + 剪枝)

    Infinite Fraction Path Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java ...

  5. php 操作Redis发送短信

    循环查询redis队列里面的数据 然后提交数据后将反馈信息再写入另一个 redis list里面 代码 <?php /** * System Name: sent message * User: ...

  6. GUI自动化测试中优化测试用例思维方法

    1.测试脚本与数据解耦(数据驱动) 让操作相同但是数据不同的测试可以通过同一 套自动化测试脚本来实现,只是在每次测试执行时提供不同的测试输入数据. 2.页面对象模型(POM) 以页面为单位来封装页面上 ...

  7. Redux 关系图解

    Redux是一款状态管理库,并且提供了react-redux库来与React亲密配合, 但是总是傻傻分不清楚这2者提供的API和相应的关系.这篇文章就来理一理. Redux Redux 三大核心 Re ...

  8. Cocos2d-x-javaScript 的webSocket的代码

    var WebSocket = WebSocket || window.WebSocket || window.MozWebSocket; var WebSocketManager = cc.Clas ...

  9. 利用AXI-DMA批量发送数据到DMA

    1.1 主函数 int main(void) { XGpio_Initialize(&Gpio, AXI_GPIO_DEV_ID); XGpio_SetDataDirection(&G ...

  10. div和span互换

    div是块级元素,它不论大小默认占一行,而且可以设置宽高以及外边距span是行内元素,它占它自身大小的位置,而且不能设置宽高以及边距同时div也可以变为span (display:inline),这样 ...