Check Corners HDU - 2888(二维RMQ)
就是板题。。
查询子矩阵中最大的元素。。。然后看看是不是四个角落的 是就是yes 不是就是no 判断一下就好了
#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 n, m;
int dp[maxn][maxn][][], a[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]; return max(max(m1, m2), max(m3, m4)); } int main()
{
while(cin>> n >> m)
{
rap(i, , n)
rap(j, , m)
{
scanf("%d", &a[i][j]);
dp[i][j][][] = a[i][j];
}
for (int i = ; ( << i) <= n; i++) {
for (int j = ; ( << j) <= m; j++) {
if (i == && j == ) continue;
for (int row = ; row + ( << i) - <= n; row++)
for (int col = ; col + ( << j) - <= m; 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]);
else dp[row][col][i][j] = max(dp[row][col][i][j - ], dp[row][col + ( << (j - ))][i][j - ]);
}
}
}
int q;
scanf("%d", &q);
while(q--)
{
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
int h = rmq(x1, y1, x2, y2);
int flag = ;
if(a[x1][y1] == h || a[x2][y2] == h || a[x1][y2] == h || a[x2][y1] == h)
flag = ;
printf("%d %s\n", h, flag?"yes":"no");
}
} return ;
}
Check Corners HDU - 2888(二维RMQ)的更多相关文章
- 【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 ...
- hduacm 2888 ----二维rmq
http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题 直接用二维rmq 读入数据时比较坑爹 cin 会超时 #include <cstdio& ...
- 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】
<题目链接> <转载于 >>> > 题目大意: 给出一个N*M的矩阵,并且给出该矩阵上每个点对应的值,再进行Q次询问,每次询问给出代询问子矩阵的左上顶点和右下 ...
- 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为右上角的坐标.求此子矩阵中元素最大值,判断最大值是否在子矩阵四个 ...
- hdu2888 二维RMQ
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
随机推荐
- vue 过滤器filters的使用以及常见报错小坑(Failed to resolve filter)
今天使用vue 过滤器中发现一个小坑,网上查到的大都是不正确的解决方法,故分享给大家: 原错误代码: // 过滤器 filter:{ FdishList:function(value){ if (!v ...
- 【JUC源码解析】LinkedBlockingQueue
简介 一个基于链表的阻塞队列,FIFO的顺序,head指向的元素等待时间最长,tail指向的元素等待时间最短,新元素从队列尾部添加,检索元素从队列头部开始,队列的容量,默认是Integer#MAX_V ...
- Unity LineRenderer制作画版
Source: using System.Collections; using System.Collections.Generic; using UnityEngine; public class ...
- 提取验证码到winform上webbroswer和axwebbroswer
在网上只有webbroswer的代码,所以自己又修改了修改改成axwebbroswer的 public static class yanZhengMaHelp { //webbrowser验证码 pu ...
- VirtualBox虚拟机上安装windows7系统
1.下载Windows7的镜像文件 http://www.xitongcheng.com/jiaocheng/win7_article_24156.html 2.在虚拟机上安装Windows7 htt ...
- JY播放器【喜马拉雅FM电脑端,附带下载功能】
今天给大家带来一款神器----JY播放器.可以不用打开网页就在电脑端听喜马拉雅FM的节目,而且可以直接下载,对于我这种强迫症患者来说真的是神器.我是真的不喜欢电脑任务栏上面密密麻麻的. 目前已经支持平 ...
- 【bzm-Random CSV Data Set Config】 -jmeter - 文件中随机取参的方法,(插件自带)
文件中随机取参数的方法 Random CSV Data Set Config
- Centos7与Centos6的区别
CentOS7 修改网卡名称为eth0.eth1 方法1 修改网卡名称 cd /etc/sysconfig/network-scripts/ mv ifcfg-eno16777736 ifcfg-et ...
- LeetCode 888. Fair Candy Swap(C++)
题目: Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy that ...
- Scrum立会报告+燃尽图(Beta阶段第二周第三次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2411 项目地址:https://coding.net/u/wuyy694 ...