就是求子矩阵中最大值与最小值的差。。。

板子都套不对的人。。。。

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a, i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
int dp[maxn][maxn][][], num[maxn][maxn];
int d[maxn][maxn][][]; int rmq(int x1, int y1, int x2, int y2)
{
int kx = , ky = ;
while (( << ( + kx)) <= x2 - x1 + ) kx++;
while (( << ( + ky)) <= y2 - y1 + ) ky++;
int m1 = dp[x1][y1][kx][ky];
int m2 = dp[x2 - ( << kx) + ][y1][kx][ky];
int m3 = dp[x1][y2 - ( << ky) + ][kx][ky];
int m4 = dp[x2 - ( << kx) + ][y2 - ( << ky) + ][kx][ky];
int m5 = max(max(m1, m2), max(m3, m4)); int n1 = d[x1][y1][kx][ky];
int n2 = d[x2 - ( << kx) + ][y1][kx][ky];
int n3 = d[x1][y2 - ( << ky) + ][kx][ky];
int n4 = d[x2 - ( << kx) + ][y2 - ( << ky) + ][kx][ky];
int n5 = min(min(n1, n2), min(n3, n4)); return m5 - n5;
} int main()
{
int n, b, k;
while(~scanf("%d%d%d", &n, &b, &k))
{
rap(i, , n)
rap(j, , n)
{
scanf("%d", &num[i][j]);
dp[i][j][][] = d[i][j][][] = num[i][j];
} for (int i = ; ( << i) <= n; i++) {
for (int j = ; ( << j) <= n; j++) {
if (i == && j == ) continue;
for (int row = ; row + ( << i) - <= n; row++)
for (int col = ; col + ( << j) - <= n; col++) {
//当x或y等于0的时候,就相当于一维的RMQ了
//if(i == 0) dp[row][col][i][j] = max(dp[row][col][i][j - 1], dp[row][col + (1 << (j - 1))][i][j - 1]);
if (j == )
{
dp[row][col][i][j] = max(dp[row][col][i - ][j], dp[row + ( << (i - ))][col][i - ][j]);
d[row][col][i][j] = min(d[row][col][i - ][j], d[row + ( << (i - ))][col][i - ][j]);
}
else
{
dp[row][col][i][j] = max(dp[row][col][i][j - ], dp[row][col + ( << (j - ))][i][j - ]);
d[row][col][i][j] = min(d[row][col][i][j - ], d[row][col + ( << (j - ))][i][j - ]);
}
}
}
} while(k--)
{
int l, r;
scanf("%d%d", &l, &r);
printf("%d\n", rmq(l, r, l+b-, r+b-)); }
} return ;
}

Cornfields POJ - 2019(二维RMQ板题)的更多相关文章

  1. poj 2019 二维rmq *

    题目大意:给出一个N*N矩形,每个格子上有一个价值.询问一个b*b的矩形在左上角的位置(x,y),(x+b-1,y+b-1)这一部分的最大值-最小值是多少. 模板题 #include <stdi ...

  2. poj2019 二维RMQ裸题

    Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions:8623   Accepted: 4100 Descrip ...

  3. hdu 2888 二维RMQ模板题

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

  4. poj2019 二维RMQ模板题

    和hdu2888基本上一样的,也是求一个矩阵内的极值 #include<iostream> #include<cstring> #include<cstdio> # ...

  5. POJ 2019 Cornfields [二维RMQ]

    题目传送门 Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7963   Accepted: 3822 ...

  6. HDU 2888:Check Corners(二维RMQ)

    http://acm.hdu.edu.cn/showproblem.php?pid=2888 题意:给出一个n*m的矩阵,还有q个询问,对于每个询问有一对(x1,y1)和(x2,y2),求这个子矩阵中 ...

  7. POJ 2019 Cornfields (二维RMQ)

    Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4911   Accepted: 2392 Descri ...

  8. HDU 2888 Check Corners (模板题)【二维RMQ】

    <题目链接> <转载于 >>> > 题目大意: 给出一个N*M的矩阵,并且给出该矩阵上每个点对应的值,再进行Q次询问,每次询问给出代询问子矩阵的左上顶点和右下 ...

  9. hduacm 2888 ----二维rmq

    http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题  直接用二维rmq 读入数据时比较坑爹  cin 会超时 #include <cstdio& ...

随机推荐

  1. windows下安装,配置redis以及可视化客户端redisClient的安装及基本使用

    一. Window 下安装 下载地址:https://github.com/MSOpenTech/redis/releases. Redis 支持 32 位和 64 位.这个需要根据你系统平台的实际情 ...

  2. 解决Extjs有IE下z-index属性的问题

    在用Extjs时,有时候,在Google浏览器上面没有任何问题,但是相同的页面在IE下面就会有问题,直接报错,点击中断,进行后可以看到如下的信息: Google里面没这个问题,加一句代码就能解决在窗体 ...

  3. html表单总结

    总结了下html表单: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  4. Java or Python?测试开发工程师如何选择合适的编程语言?

    很多测试开发工程师尤其是刚入行的同学对编程语言和技术栈选择问题特别关注,毕竟掌握一门编程语言要花不少时间成本,也直接关系到未来的面试和就业(不同企业/项目对技术栈要求也不一样),根据自身情况做一个相对 ...

  5. .net core 2.1.3可能引发Could not load file or assembly XXXXX的错误

    参考文档: https://github.com/aspnet/Home/issues/3503 写在前面 感觉自己现在干的活离开发越来越远了啊,不过也很好,每天能学到不少东西,中文的,英文的,永远也 ...

  6. 论文笔记:Visual Object Tracking based on Adaptive Siamese and Motion Estimation Network

    Visual Object Tracking based on Adaptive Siamese and Motion Estimation 本文提出一种利用上一帧目标位置坐标,在本帧中找出目标可能出 ...

  7. ES6的新特性(6)——正则的扩展

    正则的扩展 RegExp 构造函数 在 ES5 中,RegExp构造函数的参数有两种情况. 第一种情况是,参数是字符串,这时第二个参数表示正则表达式的修饰符(flag). var regex = ne ...

  8. Leftmost Digit(数学)

    Description Given a positive integer N, you should output the leftmost digit of N^N.   Input The inp ...

  9. Scrum立会报告+燃尽图(十一月十九日总第二十七次):功能开发与修复上一阶段bug

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284 项目地址:https://git.coding.net/zhang ...

  10. Python:列表操作总结

    一.创建一个列表 只要把逗号分隔的不同数据项使用方括号括起来即可 list1=['physics','chemistry',1997,2000] list2=[1,2,3,4,5,6,7] [注]:1 ...