HDU_2888_Check Corners
Check Corners
Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3247 Accepted Submission(s): 1173
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.
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
13 no
20 yes
4 yes
- 二维区间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的更多相关文章
- CSS3 笔记一(Rounded Corners/Border Images/Backgrounds)
CSS3 Rounded Corners The border-radius property is a shorthand property for setting the four border- ...
- HDU2888 Check Corners
Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all integer numbers ( 1 ...
- 【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 ...
- hdu2188 Check Corners
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Hdu 2888 Check Corners (二维RMQ (ST))
题目链接: Hdu 2888 Check Corners 题目描述: 给出一个n*m的矩阵,问以(r1,c1)为左上角,(r2,c2)为右下角的子矩阵中最大的元素值是否为子矩阵的顶点? 解题思路: 二 ...
- Android 用代码设置Shape,corners,Gradient
网上查找资料 记录学习 int strokeWidth = 5; // 3dp 边框宽度 int roundRadius = 15; // 8dp 圆角半径 int strokeColor = Col ...
- HDU-2888 Check Corners 二维RMQ
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题.解题思路如下(转载别人写的): dp[row][col][i][j] 表示[row,ro ...
- 【CSS3】Advanced1:Rounded Corners
1.Border radius The border-radius property can be used to working clockwise from top-left set border ...
- 【HDOJ】2888 Check Corners
二维RMQ. /* 2888 */ #include <iostream> #include <algorithm> #include <cstdio> #incl ...
随机推荐
- par函数col参数-控制颜色
col参数用来控制颜色,其实有一些列的颜色相关的参数,都是以col 开头 col : 控制图片中点,文字以及绘图边框的颜色,代码示例: par(col = "red") plot( ...
- Graphviz 对网状结构进行可视化
Graphviz 是一款开源的,免费的图结构的可视化软件,只需要描述清楚图中的顶点,边的信息,Graphviz 可以自动化的对图进行布局,生成对应的图片: Graphviz 采用DOT 的这种语言来描 ...
- samtools flags 的含义
对于双端比对的数据,生成的BAM文件中,R1端序列和R2端序列的标识符是一样的,之前一直不知道如何根据bam文件区分哪条序列是R1端,哪条序列是R2端,昨天仔细研究了一下,原来代表R1端和R2端的信息 ...
- Spring-bean的作用域
在大多数情况下,单例bean是很理想的方案.初始化和垃圾回收对象实例所带来的的成本只留给一些小规模任务,在这些任务中,让对象保持无状态并且在应用中反复重用这些对象可能并不合理.在这种情况下,将clas ...
- HBase学习之深入理解Memstore-6
MemStore是HBase非常重要的组成部分,深入理解MemStore的运行机制.工作原理.相关配置,对HBase集群管理以及性能调优有非常重要的帮助. HBase Memstore 首先通过简 ...
- Unity文件操作路径
Unity3D中的资源路径: Application.dataPath:此属性用于返回程序的数据文件所在文件夹的路径.例如在Editor中就是Assets了. Application.streamin ...
- javascript在字符串中提取网址并替换成超链接
var str = " http://wasmip.baidu.com.cn/mip/km/archives/km_archives_main/kmArchivesMain.do?metho ...
- retinex相关代码汇总
混合方法 SSR.m matlab代码,本来是RGB,改成了处理灰度图像的. %%%%%%%%%%%%%%%RGB normalisation%%%%%%%%%%%%%%%%%%%%%% %its c ...
- NHibernate实例
1. 下载相关资源: 下载NHibernate.下载地址: http://nhforge.org/Default.aspx 下载微软Northwind示例数据库,下载地址:http://www.mic ...
- Duilib教程-HelloDuilib及DuiDesigner的简单使用
一.HelloDuilib 1. 首先理解DUILIB显示的一个基本流程,如下图: 在Duilib中,WindowImplBase 这个类代表了图中 “CWndClass”. 所以我们需要做的是: 1 ...