题目链接:点击传送

MINSUB - Largest Submatrix

no tags 

You are given an matrix M (consisting of nonnegative integers) and an integer K.  For any submatrix of M' of M define min(M') to be the minimum value of all the entries of M'.  Now your task is simple:  find the maximum value of min(M') where M' is a submatrix of M of area at least K (where the area of a submatrix is equal to the number of rows times the number of columns it has).

Input

The first line contains a single integer T (T ≤ 10) denoting the number of test cases, T test cases follow.  Each test case starts with a line containing three integers, R (R ≤ 1000), C (C ≤ 1000) and K (K ≤ R * C) which represent the number of rows, columns of the matrix and the parameter K.  Then follow R lines each containing C nonnegative integers, representing the elements of the matrix M.  Each element of M is ≤ 10^9

Output

For each test case output two integers:  the maximum value of min(M'), where M' is a submatrix of M of area at least K, and the maximum area of a submatrix which attains the maximum value of min(M').  Output a single space between the two integers.

Example

Input:
2
2 2 2
1 1
1 1
3 3 2
1 2 3
4 5 6
7 8 9 Output:
1 4
8 2

题意:给你一个n*m的矩阵,求以一个最小值为m的最大矩阵面积s需要大于等于K

思路:二分答案,check怎么写呢。。

   类似bzoj 3039这题;

  利用单调栈,求最大子矩阵面积;

   将check的x,大于等于x的值均改成1,求1的最大面积;

   枚举每个位置,以该位置能最大的上升的位置为权值;

   例如:

   1 0 1            1  0  1

   1 1 0    -->   2  1   0

   1 0 1            3  0  1

   利用单调栈查找 以该权值为最大值最多可以往左和往右延伸最大长度;

   详见代码

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e3+,M=1e6+,inf=;
const ll INF=1e18+,mod=1e9+;
int a[N][N],b[N][N];
int l[N],r[N],s[N];
int dp[N][N];
int n,m,k;
int check(int x)
{
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
b[i][j]=(a[i][j]>=x);
memset(dp,,sizeof(dp));
int ans=;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
if(b[i][j])dp[i][j]=dp[i-][j]+;
else dp[i][j]=;
dp[i][]=dp[i][m+]=-;
int si=;
s[++si]=;
for(int j=;j<=n;j++)
{
while(dp[i][s[si]]>=dp[i][j])si--;
l[j]=s[si];
s[++si]=j;
}
si=;
s[++si]=m+;
for(int j=m;j>=;j--)
{
while(dp[i][s[si]]>=dp[i][j])si--;
r[j]=s[si];
s[++si]=j;
}
for(int j=;j<=m;j++)
ans=max(ans,(r[j]-l[j]-)*dp[i][j]);
}
return ans;
}
int main()
{
int T,cas=;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%d",&a[i][j]);
int st=;
int en=1e9+,ans=-;
while(st<=en)
{
int mid=(st+en)>>;
if(check(mid)>=k)
{
ans=mid;
st=mid+;
}
else
en=mid-;
}
printf("%d %d\n",ans,check(ans));
}
return ;
}

spoj MINSUB 单调栈+二分的更多相关文章

  1. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

  2. bzoj 4709 [Jsoi2011]柠檬——单调栈二分处理决策单调性

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4709 题解:https://blog.csdn.net/neither_nor/articl ...

  3. BZOJ1012最大数 [JSOI2008] 单调栈+二分

    正解:单调栈+二分查找(or,线段树? 解题报告: 拿的洛谷的链接quq 今天尝试学习了下单调栈,然后就看到有个博客安利了这个经典例题?于是就去做了,感觉还是帮助了理解趴quqqqqq 这题,首先,一 ...

  4. 51NOD 1962 区间计数 单调栈+二分 / 线段树+扫描线

     区间计数   基准时间限制:1.5 秒 空间限制:262144 KB 分值: 80   两个数列 {An} , {Bn} ,请求出Ans, Ans定义如下: Ans:=Σni=1Σnj=i[max{ ...

  5. 【bzoj4237】稻草人 分治+单调栈+二分

    题目描述 JOI村有一片荒地,上面竖着N个稻草人,村民们每年多次在稻草人们的周围举行祭典. 有一次,JOI村的村长听到了稻草人们的启示,计划在荒地中开垦一片田地.和启示中的一样,田地需要满足以下条件: ...

  6. 洛谷P1823 [COI2007] Patrik 音乐会的等待(单调栈+二分查找)

    洛谷P1823 [COI2007] Patrik 音乐会的等待(单调栈+二分查找) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1333275 这个题不是很 ...

  7. 【洛谷P1823】音乐会的等待 单调栈+二分

    题目大意:给定一个长度为 N 的序列,定义两个数 \(a[i],a[j]\) 相互看得见,意味着 \(\forall k\in [i+1,j-1],a[k]\le a[i],a[k]\le a[j]\ ...

  8. BZOJ 2388--旅行规划(分块&单调栈&二分)

    2388: 旅行规划 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 405  Solved: 118[Submit][Status][Discuss] ...

  9. 【BZOJ5083】普及 单调栈+二分+RMQ

    [BZOJ5083]普及 Description 有一个长度为n的字符串,每一位只会是p或j.你需要取出一个子串S(从左到右或从右到左一个一个取出),使得 不管是从左往右还是从右往左取,都保证每时每刻 ...

随机推荐

  1. Word Add-in 函数调用顺序

    这个图表明的函数的调用顺序,主要代码如下: // MyAddin.cpp : Implementation of DLL Exports. // Note: Proxy/Stub Informatio ...

  2. MVC5 新建项目里不包含jquery.unobtrusive-ajax.js(MVC5异步表单的问题)解决方法

    Asp.NET MVC 5 高级编程第5版.pdf 中有解决方法: 用NUGET程序包管理器控制台安装下面这两个文件 Install-Package jQuery –version 1.10.2 In ...

  3. Struts2-综合项目

    综合项目:视频后台管理系统 开发环境:Tomcat6(服务器)+jdk6(windows操作系统) 使用技术:struts2(后台)+jsp(前台显示)+ajax(信息传递)+json(服务器响应前台 ...

  4. 圆锥体完全均衡下重力异常正演 [MATLAB]

    在完全均衡的模型下,若地表有一圆锥体(山峰等),计算跨越山顶的截面上所得到的各种重力异常. 地壳密度 $kg\cdot m^{-3}$ 上地幔密度 $g\cdot cm^{-3}$ 地表地形圆锥体半径 ...

  5. 搭建Python3的jupyter notebook服务器

    摘要:搭建Python3 jupyter notebook. 激活Python3后,进入Python交互环境 1. 登陆远程服务器 2. 生成配置文件 1. $jupyter notebook --g ...

  6. 对使用wordpress做开发的童鞋的提醒

    [1.]WordPress 4.7.2 以及之前的所有版本都存在以下6个安全问题:记得及时升级啊. 通过媒体文件的元数据的跨网站脚本(XSS)控制字符可以欺骗重定向网址验证管理员可以使用插件删除功能删 ...

  7. Gson(Google)基础

    一.所需jar包: gson-x.x.jar(本例使用的是gson-2.7.jar). 二.解析转化: 1.json字符串  < ------ >  json String str=&qu ...

  8. python 冒泡排序的总结

    冒泡排序: 思路: 3 5 1 6 2 第一次:找到这些书中最大的一个,并把它放到最后 3.5找到大的数放到第二个位置1.5 5.1找到大的数放到第三个位置1.5.1 5.6找到大的数放到第四个位置 ...

  9. 左连接LEFT JOIN 连接自己时的查询结果测试

    #左连接LEFT JOIN 连接自己时的查询结果测试 #左连接LEFT JOIN 连接自己时的查询结果(都会出现两个重复字段),两个表都有as后只能查询相等条件merchant_shop_id非nul ...

  10. 利用arcgis处理遥感栅格数据,得到省平均值数据

    1.准备全国省级行政区数据,需要有省级行政区信息,如下所示: 2.生成渔网数据,操作完成会生成一个面数据和一个点数据,我们主要用点数据进行后面的操作. 3.提取栅格数据的值到渔网点数据中. 4.将区域 ...