hdu2188 Check Corners
Check Corners
Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 858 Accepted Submission(s): 275
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
#include<iostream>
#include<cstdio>
#include<cmath>
#define maxn 309
using namespace std; int n,m,dp[maxn][maxn][][],map[maxn][maxn];
int x,y,xx,yy,q; void RMQ_pre(){
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
dp[i][j][][]=map[i][j];
int mx=log(double(n))/log(2.0);
int my=log(double(m))/log(2.0);
for(int i=;i<=mx;i++){
for(int j=;j<=my;j++){
if(i==&&j==)continue;
for(int row=;row+(<<i)-<=n;row++){
for(int col=;col+(<<j)-<=m;col++){
if(i==)
dp[row][col][i][j]=max(dp[row][col][i][j-],dp[row][col+(<<(j-))][i][j-]);
else
dp[row][col][i][j]=max(dp[row][col][i-][j],dp[row+(<<(i-))][col][i-][j]);
}
}
}
}
} int RMQ_2D(int x,int y,int xx,int yy){
int kx=log(double(xx-x+))/log(2.0);
int ky=log(double(yy-y+))/log(2.0);
int m1=dp[x][y][kx][ky];
int m2=dp[xx-(<<kx)+][y][kx][ky];
int m3=dp[x][yy-(<<ky)+][kx][ky];
int m4=dp[xx-(<<kx)+][y-(<<ky)+][kx][ky];
return max(max(m1,m2),max(m3,m4));
} int main(){
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%d",&map[i][j]);
RMQ_pre();
scanf("%d",&q);
while(q--){
scanf("%d%d%d%d",&x,&y,&xx,&yy);
int ans=RMQ_2D(x,y,xx,yy);
printf("%d ",ans);
if(ans==map[x][y]||ans==map[xx][y]||ans==map[xx][yy]||ans==map[xx][yy])
printf("yes\n");
else printf("no\n");
}
}
return ;
}
hdu2188 Check Corners的更多相关文章
- 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 ...
- 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 题意:给出一个n*m的矩阵,还有q个询问,对于每个询问有一对(x1,y1)和(x2,y2),求这个子矩阵中 ...
- HDU-2888 Check Corners 二维RMQ
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题.解题思路如下(转载别人写的): dp[row][col][i][j] 表示[row,ro ...
- 【HDOJ】2888 Check Corners
二维RMQ. /* 2888 */ #include <iostream> #include <algorithm> #include <cstdio> #incl ...
- HDU 2888 Check Corners (模板题)【二维RMQ】
<题目链接> <转载于 >>> > 题目大意: 给出一个N*M的矩阵,并且给出该矩阵上每个点对应的值,再进行Q次询问,每次询问给出代询问子矩阵的左上顶点和右下 ...
- HDU2888 Check Corners(二维RMQ)
有一个矩阵,每次查询一个子矩阵,判断这个子矩阵的最大值是不是在这个子矩阵的四个角上 裸的二维RMQ #pragma comment(linker, "/STACK:1677721600&qu ...
- Check Corners HDU - 2888(二维RMQ)
就是板题.. 查询子矩阵中最大的元素...然后看看是不是四个角落的 是就是yes 不是就是no 判断一下就好了 #include <iostream> #include <cs ...
随机推荐
- 【HackerRank】QuickSort(稳定快排,空间复杂度O(n))
QuickSort In the previous challenge, you wrote a partition method to split an array into 2 sub-array ...
- freeswitch中集成使用ekho实现TTS功能一
Linux下安装freeswitch并集成ekho实现TTS 1. linux下安装freeswitch就不多介绍了,具体链接网址: http://www.8000hz.com/archives/14 ...
- 主攻ASP.NET MVC4.0之重生:Jquery Mobile 表单元素
相关代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <tit ...
- windows10添加电源计划修改的快捷方案
转自:http://news.mydrivers.com/1/431/431346.htm 由于目前的Windows 10预览版在UI方面还未优化到位,所以某些设置选项要想找出来是很难的,这时候如果能 ...
- 微软官网的office外接程序开发
链接地址:https://msdn.microsoft.com/zh-cn/library/fp161347.aspx
- 树 List Leaves 【用数组模拟了树状结构建树+搜索叶子节点+按照特殊规律输出每个叶子节点】
Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. I ...
- oracle 序列改值
1.oracle 序列改值 执行:Alter Sequence SQ_RM_FRAME Increment By 100; 执行:Select SQ_RM_FRAME.NextVal From Dua ...
- XXL-Job路由策略
企业项目中所有的任务调动通过XXL-Job 去管理调度 路由策略类似于Nginx哦 XXL-Job实际封装的是Quartz. 关于分片广播,执行器集群部署时候,任务路由策略选择“”分片广播”情况下,一 ...
- 在虚拟机里安装ubuntu
1.下载ubuntu镜像文件 https://mirrors.aliyun.com/ubuntu-releases/17.04/ubuntu-17.04-desktop-amd64.iso 2.创建虚 ...
- Carrier-Grade Mirantis OpenStack (the Mirantis NFV Initiative), Part 1: Single Root I/O Virtualization (SR-IOV)
The Mirantis NFV initiative aims to create an NFV ecosystem for OpenStack, with validated hardware ...