poj 2019 二维rmq *】的更多相关文章

就是求子矩阵中最大值与最小值的差... 板子都套不对的人.... #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stack> #include <queue> #include &…
题目大意:给出一个N*N矩形,每个格子上有一个价值.询问一个b*b的矩形在左上角的位置(x,y),(x+b-1,y+b-1)这一部分的最大值-最小值是多少. 模板题 #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> using namespace std; ][]; ]; ][][][];//最小值 ][][][];//最大值 void initRM…
题目传送门 Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7963   Accepted: 3822 Description FJ has decided to grow his own corn hybrid in order to help the cows make the best possible milk. To that end, he's looking to build the c…
Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4911   Accepted: 2392 Description FJ has decided to grow his own corn hybrid in order to help the cows make the best possible milk. To that end, he's looking to build the cornfie…
Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2513    Accepted Submission(s): 904 Problem Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all intege…
http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题  直接用二维rmq 读入数据时比较坑爹  cin 会超时 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; ][]; void rmq_init(int n, int m) { ; i <= n; i++) { ; j <= m; j++) dp[…
Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2377    Accepted Submission(s): 859 Problem Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all intege…
<题目链接> <转载于 >>> > 题目大意: 给出一个N*M的矩阵,并且给出该矩阵上每个点对应的值,再进行Q次询问,每次询问给出代询问子矩阵的左上顶点和右下顶点,问该子矩阵的最大值是多少,并且判断该最值是否在该子矩阵的四个顶角上. 解题分析: 很明显求二维区间内的最值,需要用到二维RMQ,其中dp[i][j][k][l]表示左上角为(i,j),右下角为(i + 2 ^ k - 1, j + 2 ^ l - 1)这个矩形内的最值.注意这个四维数组不要开得太大,否则…
有一个矩阵,每次查询一个子矩阵,判断这个子矩阵的最大值是不是在这个子矩阵的四个角上 裸的二维RMQ #pragma comment(linker, "/STACK:1677721600") #include <map> #include <set> #include <stack> #include <queue> #include <cmath> #include <ctime> #include <vec…
Little Tommy is playing a game. The game is played on a 2D N x N grid. There is an integer in each cell of the grid. The rows and columns are numbered from 1 to N. At first the board is shown. When the user presses a key, the screen shows three integ…
Problem Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all integer numbers ( 1 <= i <= m, 1 <= j <= n ). Now he selects some sub-matrices, hoping to find the maximum number. Then he finds that there may be more tha…
题目描述 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. 输入 第一行为3个整数,分别表示a,b,n的值第二行至第a+1行每行为b个非负整数,表示矩阵中相应位置上的数.每行相邻两数之间用一空格分隔.100%的数据2<=a,b<=1000,n<=a,n<=b,n<=1000 输出 仅一个整数,为a*b矩阵中所有“n*n正方形区域中的最大整数和最小整数的差值”的最小值. 样例输入 5 4 2 1 2 5 6 0 1…
点此看题面 大致题意: 求出一个矩阵中所有\(n*n\)正方形中极差的最小值. 另一种做法 听说这题可以用单调队列去做,但是我写了一个二维\(RMQ\). 二维\(RMQ\) \(RMQ\)相信大家都会的,而 二维\(RMQ\) 其实与普通\(RMQ\)是没什么区别的. 我们可以用\(Max_{i,j,k}\)来表示\((i,j)\sim(i+2^k,j+2^k)\)这个矩阵内的最大值,\(Min_{i,j,k}\)同理. 由于求的是一个正方形内的最大值与最小值,所以\((i,j)\sim(x,…
Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1646    Accepted Submission(s): 597 Problem Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all integer…
https://ac.nowcoder.com/acm/contest/700/I 二维RMQ,贴个板子,注意爆内存,用char就可以了,char也可以存负数. 然后二分枚举对角线长度,理由很简单. 矩阵变大,极值只会变大不会变小.满足单调性. #include<bits/stdc++.h> using namespace std; #define MAXN 501 int n,m,g; int rec[MAXN][MAXN]; char dp[MAXN][MAXN][11][11]; cha…
理想的正方形 省队选拔赛河南  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 大师 Master       题目描述 Description 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. 输入描述 Input Description 第一行为3个整数,分别表示a,b,n的值 第二行至第a+1行每行为b个非负整数,表示矩阵中相应位置上的数.每行相邻两数之间用一空格分隔. 输出描述 Output Descr…
题目描述 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. 输入输出格式 输入格式: 第一行为3个整数,分别表示a,b,n的值 第二行至第a+1行每行为b个非负整数,表示矩阵中相应位置上的数.每行相邻两数之间用一空格分隔. 输出格式: 仅一个整数,为a*b矩阵中所有“n*n正方形区域中的最大整数和最小整数的差值”的最小值. 输入输出样例 输入样例#1: 5 4 2 1 2 5 6 0 17 16 0 16 17 2 1 2 10 2…
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 nam…
Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions:8623   Accepted: 4100 Description FJ has decided to grow his own corn hybrid in order to help the cows make the best possible milk. To that end, he's looking to build the cornfiel…
题目:点这里 题意:给出一个n*m的矩阵,然后又Q个询问:每个询问有x1,y1,x2,y2,x1,y1为子矩阵的左上角坐标,x2,y2为右上角的坐标.求此子矩阵中元素最大值,判断最大值是否在子矩阵四个角上,在就输出yes,否则输出no. 分析:二维RMQ直接上代码. #include<iostream> #include<stdio.h> #include<algorithm> #include<string.h> using namespace std;…
相比以前的RMQ不同的是,这是一个二维的ST算法 #include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; #define N 300 ][][N][N]; ][][N][N]; ///int lg[N]; int getmax(int a,int b,int c,int d) { return max(max(a,b),max(c,d…
求二维ST表 ;k<=;k++) ;l<=;l++) ;i<=n;i++) ;j<=m;j++){ <<(l-)),m+),tx=min(n+,i+(<<(k-))); &&l==) continue;else ) rmq[i][j][k][l]=max(rmq[i][ty][k][l-],rmq[i][j][k][l-]);else ) rmq[i][j][k][l]=max(rmq[tx][j][k-][l],rmq[i][j][k-][…
题目链接 给一个01矩阵, 然后每个询问给出两个坐标(x1, y1), (x2, y2). 问你这个范围内的最大全1正方形的边长是多少. 我们dp算出以i, j为右下角的正方形边长最大值. 然后用二维st表预处理出所有的最大值. 对于每个询问, 我们二分一个值mid, 查询(x1 + mid -1, y1 + mid -1), (x2, y2)这个范围内的最大值是否大于mid .如果大于的话就说明在(x1, y1), (x2, y2)范围内存在一个边长为mid的正方形. #include <bi…
这题求范围最小值,RMQ正好是用来解决这方面的.所以再适合只是了,又是离线静态输入输出的,所以时间比二维线段树快. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<queue> #include<set> #include<cmath> #include<bit…
int main(){ ; i <= n; i++) ; j <= m; j++) { scanf("%d", &val[i][j]); dp[i][j][][] = val[i][j]; } ; ( << i) <= n; i++) { ; ( << j) <= m; j++) { && j == ) continue; ; row + ( << i) - <= n; row++) ; col…
题:https://codeforces.com/contest/1301/problem/E 题意:给个n*m的图形,q个询问,每次询问问询问区间最大的合法logo的面积是多少 分析:由于logo是由4个同色的小正方形组成的,所以我们先考虑一个数组val[i][j]表示[i][j]位置为‘R' , [i+1][j]位置为’Y‘,[i][j+1]位置为’G‘,[i+1][j+1]位置为’B'所能形成的最大图案边长是多少: 因为这样就只要预处理‘R’正方形沿着左上能形成的最大正方形,“Y”沿着左下…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题.解题思路如下(转载别人写的): dp[row][col][i][j] 表示[row,row+2^i-1]x[col,col+2^j-1] 二维区间内的最小值这是RMQ-ST算法的核心: 倍增思想== min( [row,row+ 2^(i-1)-1]x[col,col+2^j-1], [row+2^(i-1),row+2^i-1]x[col,col+2^j-1] )= min(dp[r…
针对一些二维区间最值问题,用一维RMQ来解决显然是不够的.所以,要改进算法.鉴于网上没有PASCAL版的RMQ标程与解析,所以小可在这里简单的讲一下. 核心思想和一维的一样,只是在计算区间时略有不同.用数组F[i,j,k]表示以i,j为左上角的矩形,长度为(1 shl k),然后在循环时取四个矩形的最值,具体伪代码如下: for k:=1 to x do // x为要处理矩形的最大边长的trunc(log2max)值  for i:=1 to n+1-(1 shl k) do  for j:=1…
题意:给你一个n*n的矩阵,让你从中圈定一个小矩阵,其大小为b*b,有q个询问,每次询问告诉你小矩阵的左上角,求小矩阵内的最大值和最小值的差. 解题关键:二维st表模板题. 预处理复杂度:$O({n^2}\log n)$ 查询复杂度:$O(n)$ #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<iostream> #include&…
题目链接: Hdu 2888 Check Corners 题目描述: 给出一个n*m的矩阵,问以(r1,c1)为左上角,(r2,c2)为右下角的子矩阵中最大的元素值是否为子矩阵的顶点? 解题思路: 二维区间最值查询,可以用二维的ST算法,dp[x][y][i][j]表示x轴上[x,x+(1<<i)-1]与y轴上[y-(1<<j)+1,y]组成的子矩阵中的最值.预处理的时候处理出来子矩阵的最值,查询的时候对于x,y轴上的查询区间[m, n],都要找到一个k,k满足 n-m+1 <…