HDU 2888:Check Corners(二维RMQ)
http://acm.hdu.edu.cn/showproblem.php?pid=2888
题意:给出一个n*m的矩阵,还有q个询问,对于每个询问有一对(x1,y1)和(x2,y2),求这个子矩阵中的最大值,和判断四个角有没有等于这个最大值的。
思路:二维RMQ模板题。注意内存卡的挺紧的。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define N 301
int dp[N][N][][], mp[N][N], n, m, x1, x2, y11, y2;
// 内存刚好 30704kB 卡着过了 void Init() {
for(int i = ; i <= n; i++) for(int j = ; j <= m; j++) dp[i][j][][] = mp[i][j];
int A = (int)(log(n) / log()), B = (int)(log(m) / log());
for(int j = ; j <= A; j++) {
for(int y = ; y <= B; y++) {
if(j == && y == ) continue;
for(int i = ; i + ( << j) - <= n; i++)
for(int x = ; x + ( << y) - <= m; x++)
if(j) dp[i][x][j][y] = max(dp[i][x][j-][y], dp[i+(<<(j-))][x][j-][y]);
else dp[i][x][j][y] = max(dp[i][x][j][y-], dp[i][x+(<<(y-))][j][y-]);
}
}
} int Query() {
int A = (int)(log(x2 - x1 + ) / log()), B = (int)(log(y2 - y11 + ) / log());
int a = dp[x1][y11][A][B];
int b = dp[x2-(<<A)+][y11][A][B];
int c = dp[x1][y2-(<<B)+][A][B];
int d = dp[x2-(<<A)+][y2-(<<B)+][A][B];
return max(a, max(b, max(c, d)));
} bool check(int val) {
if(mp[x1][y11] == val || mp[x2][y2] == val || mp[x1][y2] == val || mp[x2][y11] == val) return true;
return false;
} int main() {
while(~scanf("%d%d", &n, &m)) {
for(int i = ; i <= n; i++) for(int j = ; j <= m; j++) scanf("%d", &mp[i][j]);
int q; scanf("%d", &q);
Init();
while(q--) {
scanf("%d%d%d%d", &x1, &y11, &x2, &y2);
int val = Query();
printf("%d ", val);
if(check(val)) puts("yes");
else puts("no");
}
}
return ;
}
HDU 2888:Check Corners(二维RMQ)的更多相关文章
- Hdu 2888 Check Corners (二维RMQ (ST))
题目链接: Hdu 2888 Check Corners 题目描述: 给出一个n*m的矩阵,问以(r1,c1)为左上角,(r2,c2)为右下角的子矩阵中最大的元素值是否为子矩阵的顶点? 解题思路: 二 ...
- HDU-2888 Check Corners 二维RMQ
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题.解题思路如下(转载别人写的): dp[row][col][i][j] 表示[row,ro ...
- HDU 2888 Check Corners (模板题)【二维RMQ】
<题目链接> <转载于 >>> > 题目大意: 给出一个N*M的矩阵,并且给出该矩阵上每个点对应的值,再进行Q次询问,每次询问给出代询问子矩阵的左上顶点和右下 ...
- 【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 ...
- hdu 2888 二维RMQ模板题
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 2888 二维RMQ
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU2888 Check Corners(二维RMQ)
有一个矩阵,每次查询一个子矩阵,判断这个子矩阵的最大值是不是在这个子矩阵的四个角上 裸的二维RMQ #pragma comment(linker, "/STACK:1677721600&qu ...
- 二维RMQ hdu 2888
题目:点这里 题意:给出一个n*m的矩阵,然后又Q个询问:每个询问有x1,y1,x2,y2,x1,y1为子矩阵的左上角坐标,x2,y2为右上角的坐标.求此子矩阵中元素最大值,判断最大值是否在子矩阵四个 ...
- hduacm 2888 ----二维rmq
http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题 直接用二维rmq 读入数据时比较坑爹 cin 会超时 #include <cstdio& ...
随机推荐
- Lexer的设计--下(5)
一个礼拜之后我终于从成都回来了, 从今天开始更新会恢复... 一点小的改进 写lex()的时候距离我上一次写已经一个礼拜了, 所以我回顾了一下之前的代码, 发现还是有瑕疵. 比如考虑到一个较短的程序, ...
- delphi资源文件的使用
delphi资源文件的使用 资源文件(*.res)通过编译指令 $R 关联, 譬如工程文件 Project1 中的 {$R *.res} 就是关联 Project1.res 资源文件, 我们直接写作 ...
- Microsoft Enterprise Library 5.0 系列(三)
一.简介及用途 在实际的项目开发中,我们总会需要对数据进行验证,以保证数据的可靠性,而为了使这些验证可以在不同的地方进行复用(如winform.web.WPF等),就需要将验证进行封装,EntLib的 ...
- C# dotnetcore2.0结合Selenium搜索网页
using System; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; namespace ConsoleApp_Selenium { c ...
- SqlServer判断数据库、表、字段、存储过程、函数是否存在
原文:SqlServer判断数据库.表.字段.存储过程.函数是否存在 判断数据库是否存在 if exists (select * from sys.databases where name = '数据 ...
- C#图片灰度处理(位深度24→位深度8),用灰度数组byte[]新建一个8位灰度图像Bitmap 。
原文:C#图片灰度处理(位深度24→位深度8) #region 灰度处理 /// <summary> /// 将源图像灰度化,并转化为8位灰度图像. /// </summary> ...
- 一篇文章搞定JS类型转换
啥要说这个东西?一道面试题就给我去说它的动机.题如下: var bool = new Boolean(false); if (bool) { alert('true'); } else { alert ...
- NUMA 架构
NUMA架构的CPU -- 你真的用好了么? - http://cenalulu.github.io/linux/numa/ SQL Server 如何支持 NUMA - https://docs.m ...
- Qt多线程学习-用例子来理解多线程
文章出处:DIY部落(http://www.diybl.com/course/3_program/c/c_js/20090303/157373_3.html) POINT 1:QThread类的实例与 ...
- 【canvas】基础练习二 文字
demo1 fillText strokeText绘制文字 <!DOCTYPE html> <html lang="en"> <head> &l ...