Check Corners

Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3247    Accepted Submission(s): 1173

Problem Description
Paul draw a big m*n matrix A last month, whose entries Ai,j are all integer numbers ( 1 <= i <= m, 1 <= j <= n ). Now he selects some sub-matrices, hoping to find the maximum number. Then he finds that there may be more than one maximum number, he also wants to know the number of them. But soon he find that it is too complex, so he changes his mind, he just want to know whether there is a maximum at the four corners of the sub-matrix, he calls this “Check corners”. It’s a boring job when selecting too many sub-matrices, so he asks you for help. (For the “Check corners” part: If the sub-matrix has only one row or column just check the two endpoints. If the sub-matrix has only one entry just output “yes”.)
 
Input
There are multiple test cases.

For each test case, the first line contains two integers m, n (1 <= m, n <= 300), which is the size of the row and column of the matrix, respectively. The next m lines with n integers each gives the elements of the matrix which fit in non-negative 32-bit integer.

The next line contains a single integer Q (1 <= Q <= 1,000,000), the number of queries. The next Q lines give one query on each line, with four integers r1, c1, r2, c2 (1 <= r1 <= r2 <= m, 1 <= c1 <= c2 <= n), which are the indices of the upper-left corner and lower-right corner of the sub-matrix in question.

 
Output
For each test case, print Q lines with two numbers on each line, the required maximum integer and the result of the “Check corners” using “yes” or “no”. Separate the two parts with a single space.
 
Sample Input
4 4
4 4 10 7
2 13 9 11
5 7 8 20
13 20 8 2
4
1 1 4 4
1 1 3 3
1 3 3 4
1 1 1 1
 
Sample Output
20 no
13 no
20 yes
4 yes
 
Source
 
  • 二维区间max,打二维ST表
  • dp[i][j][e][f]表明从矩阵左上角(i,j)开始宽度范围是2^e,高度范围是2^f的矩形
 #include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
const int maxn = 1e5 + ;
const int inf = 0x3f3f3f3f ;
const int npos = - ;
const int mod = 1e9 + ;
const int mxx = + ;
const double eps = 1e- ;
const double PI = acos(-1.0) ; int max4(int a, int b, int c, int d){
return max(max(a,b),max(c,d));
}
int m, n, fac[], dp[][][][];
int X1, Y1, X2, Y2, ans, mx, q;
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
for(int i=;i<;i++)
fac[i]=(<<i);
while(~scanf("%d %d",&m,&n)){
for(int i=;i<=m;i++)
for(int j=;j<=n;j++)
scanf("%d",&dp[i][j][][]);
int rk=(int)(log((double)m)/log(2.0));
int ck=(int)(log((double)n)/log(2.0));
for(int e=;e<=rk;e++)
for(int f=;f<=ck;f++)
if(e || f)
for(int i=;i+fac[e]-<=m;i++)
for(int j=;j+fac[f]-<=n;j++)
if(!e)
dp[i][j][e][f]=max(dp[i][j][e][f-],dp[i][j+fac[f-]][e][f-]);
else if(!f)
dp[i][j][e][f]=max(dp[i][j][e-][f],dp[i+fac[e-]][j][e-][f]);
else
dp[i][j][e][f]=max4(dp[i][j][e-][f-],dp[i+fac[e-]][j][e-][f-],dp[i][j+fac[f-]][e-][f-],dp[i+fac[e-]][j+fac[f-]][e-][f-]);
scanf("%d",&q);
while(q--){
ans=;
scanf("%d %d %d %d",&X1,&Y1,&X2,&Y2);
rk=(int)(log((double)(X2-X1+))/log(2.0));
ck=(int)(log((double)(Y2-Y1+))/log(2.0));
mx=max4(dp[X1][Y1][rk][ck],dp[X2-fac[rk]+][Y1][rk][ck],dp[X1][Y2-fac[ck]+][rk][ck],dp[X2-fac[rk]+][Y2-fac[ck]+][rk][ck]);
if(mx==dp[X1][Y1][][]||
mx==dp[X1][Y2][][]||
mx==dp[X2][Y1][][]||
mx==dp[X2][Y2][][]){
ans=;
}
printf("%d %s\n",mx,ans?"yes":"no");
}
}
return ;
}

HDU_2888_Check Corners的更多相关文章

  1. CSS3 笔记一(Rounded Corners/Border Images/Backgrounds)

    CSS3 Rounded Corners The border-radius property is a shorthand property for setting the four border- ...

  2. HDU2888 Check Corners

    Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all integer numbers ( 1 ...

  3. 【HDOJ 2888】Check Corners(裸二维RMQ)

    Problem Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all integer numb ...

  4. hdu2188 Check Corners

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. Hdu 2888 Check Corners (二维RMQ (ST))

    题目链接: Hdu 2888 Check Corners 题目描述: 给出一个n*m的矩阵,问以(r1,c1)为左上角,(r2,c2)为右下角的子矩阵中最大的元素值是否为子矩阵的顶点? 解题思路: 二 ...

  6. Android 用代码设置Shape,corners,Gradient

    网上查找资料 记录学习 int strokeWidth = 5; // 3dp 边框宽度 int roundRadius = 15; // 8dp 圆角半径 int strokeColor = Col ...

  7. HDU-2888 Check Corners 二维RMQ

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题.解题思路如下(转载别人写的): dp[row][col][i][j] 表示[row,ro ...

  8. 【CSS3】Advanced1:Rounded Corners

    1.Border radius The border-radius property can be used to working clockwise from top-left set border ...

  9. 【HDOJ】2888 Check Corners

    二维RMQ. /* 2888 */ #include <iostream> #include <algorithm> #include <cstdio> #incl ...

随机推荐

  1. CentOS系统命令

    系统命令 yum命令 yum makecache yum 生成缓存 yum list installed mysql* 查看有没有安装过*包 rpm -qa | grep mysql* 查看有没有安装 ...

  2. luasql在Fedora20下的安装与使用示例

    主要参考:http://www.boll.me/archives/614 luasql安装, 在终端通过yum命令安装: yum -y install lua-sql 接下来写个测试的lua脚本文件( ...

  3. 【Java面试题】42 TreeSet里面放对象,如果同时放入了父类和子类的实例对象,那比较时使用的是父类的compareTo方法,还是使用的子类的compareTo方法,还是抛异常!

    应该是没有针对问题的确切的答案,当前的add方法放入的是哪个对象,就调用哪个对象的compareTo方法,至于这个compareTo方法怎么做,就看当前这个对象的类中是如何编写这个方法的 试验如下: ...

  4. CleanMyMac 3.7.5最强中文版_激活码_破解版_下载_注册码

    版权归作者所有,任何形式转载请联系作者.作者:缘来远去(来自豆瓣)来源:https://www.douban.com/note/612586476/ 最新版CleanMyMac 3中文版本已经发布快要 ...

  5. opengl wglsharelists

    原文地址:http://blog.csdn.net/webscaler/article/details/5873179 OpenGL 中用到多线程和多 render context 渲染的时候会用到 ...

  6. mysql在命令行中,指定要连接的数据库?

    需求描述: mysql客户端,可以在登录到mysql数据库时,指定要连接到哪个数据库 这里进行一个测试. 测试过程: 1.mysql通过-D参数指定连接到test数据库 [mysql@redhat6 ...

  7. 开源 免费 java CMS - FreeCMS1.9 移动APP生成网站列表数据

    项目地址:http://www.freeteam.cn/ 生成网站列表数据 提取同意移动APP訪问的网站列表,生成json数据到/mobile/index.html页面. 从左側管理菜单点击生成网站列 ...

  8. MVC源码

    http://aspnetwebstack.codeplex.com/ MVC源码

  9. linux连接sybase数据库-isql

    转自:http://blog.knowsky.com/196438.htm 想要linux连接sybase数据库用命令isql: isql [-U login id] [-P password] [- ...

  10. 查看磁盘读写:iotop

    iotop命令用来动态地查看磁盘IO情况,用法如下: [root@localhost ~]$ yum install -y iotop # 安装iotop命令 [root@localhost ~]$ ...