hdu2888 二维RMQ
Check Corners
Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2513 Accepted Submission(s): 904
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.
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1000000001
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
//#define pi acos(-1.0)
using namespace std;
const int MAXN = ;
int a[MAXN][MAXN],n,m,dp[MAXN][MAXN][][];
void Init()
{
for(int i = ; i <= n; i++){
for(int j = ; j <= m; j++){
dp[i][j][][] = a[i][j];
}
}
for(int pi = ; pi < ; pi++){
for(int pj = ; pj < ; pj++){
if(pi == && pj == )continue;
for(int i = ; i <= n; i++){
for(int j = ; j <= m; j++){
if(i + ( << pi) - > n || j + ( << pj) - > m)continue;
if(pi == ){
dp[i][j][pi][pj] = max(dp[i][j][pi][pj-],dp[i][j+(<<(pj-))][pi][pj-]);
}
else {
dp[i][j][pi][pj] = max(dp[i][j][pi-][pj],dp[i+(<<(pi-))][j][pi-][pj]);
}
}
}
}
}
}
void getans(int x1,int y1,int x2,int y2)
{
int kx,ky;
kx = (int)(log((double)(x2 - x1)) / log(2.0));
ky = (int)(log((double)(y2 - y1)) / log(2.0));
int ans = -INF;
ans = max(ans,dp[x1][y1][kx][ky]);
ans = max(ans,dp[x2 - ( << kx) + ][y1][kx][ky]);
ans = max(ans,dp[x1][y2 - ( << ky) + ][kx][ky]);
ans = max(ans,dp[x2 - ( << kx) + ][y2 - ( << ky) + ][kx][ky]);
printf("%d ",ans);
if(a[x1][y1] == ans || a[x1][y2] == ans || a[x2][y1] == ans || a[x2][y2] == ans)printf("yes\n");
else printf("no\n");
}
void solve()
{
int q;
scanf("%d",&q);
int x1,y1,x2,y2;
while(q--){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
getans(x1,y1,x2,y2);
}
}
int main()
{
while(~scanf("%d%d",&n,&m)){
for(int i = ; i <= n; i++){
for(int j = ; j <= m; j++){
scanf("%d",&a[i][j]);
}
}
Init();
solve();
}
return ;
}
hdu2888 二维RMQ的更多相关文章
- hdu2888 二维ST表(RMQ)
二维RMQ其实和一维差不太多,但是dp时要用四维 /* 二维rmq */ #include<iostream> #include<cstring> #include<cs ...
- HDU2888 Check Corners(二维RMQ)
有一个矩阵,每次查询一个子矩阵,判断这个子矩阵的最大值是不是在这个子矩阵的四个角上 裸的二维RMQ #pragma comment(linker, "/STACK:1677721600&qu ...
- hduacm 2888 ----二维rmq
http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题 直接用二维rmq 读入数据时比较坑爹 cin 会超时 #include <cstdio& ...
- hdu 2888 二维RMQ模板题
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 2888 Check Corners (模板题)【二维RMQ】
<题目链接> <转载于 >>> > 题目大意: 给出一个N*M的矩阵,并且给出该矩阵上每个点对应的值,再进行Q次询问,每次询问给出代询问子矩阵的左上顶点和右下 ...
- POJ 2019 Cornfields [二维RMQ]
题目传送门 Cornfields Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7963 Accepted: 3822 ...
- 【LightOJ 1081】Square Queries(二维RMQ降维)
Little Tommy is playing a game. The game is played on a 2D N x N grid. There is an integer in each c ...
- 【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 ...
- POJ 2019 Cornfields (二维RMQ)
Cornfields Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4911 Accepted: 2392 Descri ...
随机推荐
- 第16章 调色板管理器_16.4 一个DIB位图库的实现(2)
//接上一篇 //DibPal.h /*----------------------------------------------------------------- DIBPAL.H heade ...
- AC日记——密码翻译 openjudge 1.7 09
09:密码翻译 总时间限制: 1000ms 内存限制: 65536kB 描述 在情报传递过程中,为了防止情报被截获,往往需要对情报用一定的方式加密,简单的加密算法虽然不足以完全避免情报被破译,但仍 ...
- KSFramework配置表:扩展表格解析类型
解析和扩展表格 配置表示例 配置表模块在编译时,把Excel转化成TSV,并根据Excel的头部信息,生成对应的代码: 比如源码库中的Test.xlsx Excel文件,两个列头,Id和Value,其 ...
- [No000000]常用软件测试编译环境声明
程序语言这东西并不重要,重要的是你用这些语言做的事情. 操作系统:WIN8.1 X64 运行库&支持库: DirectX,Microsoft Visual C++ (VC运行库包括X86版)2 ...
- Xcode 快捷键
1.commmand +shift +k ,隐藏模拟器键盘,用户可以在真实键盘输入到模拟屏幕上.
- ajax之jsonp跨域请求
前端ajax请求代码 后台php处理代码
- Java命令行的执行参数
Java 程序命令行参数说明 启动Java程序的方式有两种: # starts a Java virtual machine, loads the specified class, and invok ...
- VS2010/VS2013怎么复制项目/拷贝项目/克隆项目
本文以vs2013为例,讲述了如何复制项目.vs2008,vs2010,vs2012等版本应操作类似 vs中的项目位于解决方案中,简单的复制粘贴是不能实现项目复制的 一.准备 原项目名称:test 目 ...
- Easyui Tree方法扩展 - getLevel(获取节点级别)
Easyui Tree一直就没有提供这个方法,以前没有用到,所以一直没怎么在意,这次自己用到了,顺便扩展了一个方法,分享给大家. $.extend($.fn.tree.methods, { getLe ...
- Linux 网络编程详解八
TCP/IP协议三次握手机制 TCP/IP是全双工通道,两端都可以读写,三次握手机制就是验证TCP/IP是否是全双工通道 1.客户端调用connect()函数,阻塞客户端进程,客户端向服务器发送数据包 ...