HDU 2888 Check Corners(二维RMQ)

并网逆变器学习笔记8---平衡桥(独立中线模块)控制 参考文献:《带独立中线模块的三相四线制逆变器中线电压脉动抑制方法》---赵文心。 阅读详情

Check Corners

Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3063    Accepted Submission(s): 1100


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 than one maximum number, he also wants to know the number of them. But soon he find that it is too complex, so he changes his mind, he just want to know whether there is a maximum at the four corners of the sub-matrix, he calls this “Check corners”. It’s a boring job when selecting too many sub-matrices, so he asks you for help. (For the “Check corners” part: If the sub-matrix has only one row or column just check the two endpoints. If the sub-matrix has only one entry just output “yes”.)
 

Input
There are multiple test cases. 

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. 
 

Output
For each test case, print Q lines with two numbers on each line, the required maximum integer and the result of the “Check corners” using “yes” or “no”. Separate the two parts with a single space.
 

Sample Input
  
4 4 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
 

Sample Output
  
20 no 13 no 20 yes 4 yes
 

Source
 

题意:

给出一个矩阵,给你几个询问,每个询问问你子矩阵中的最大值,若最大值在角上,yes,否则no。

POINT:

二维的RMQ,之前没做过。


#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;
const int N = 300+3;
int n,m;
int a[N][N];
int dp[N][N][9][9];
void prermq()
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            dp[i][j][0][0]=a[i][j];
        }
    }
    for(int a=0;1<<a<=n;a++)
    {
        for(int b=0;1<<b<=m;b++)
        {
            if(a==b&&b==0) continue;
            for(int i=1;i-1+(1<<a)<=n;i++)
            {
                for(int j=1;j-1+(1<<b)<=m;j++)
                {
                    if(a==0)
                    {
                        dp[i][j][a][b]=max(dp[i][j][a][b-1],dp[i][j+(1<<(b-1))][a][b-1]);
                    }
                    else
                        dp[i][j][a][b]=max(dp[i][j][a-1][b],dp[i+(1<<(a-1))][j][a-1][b]);
                }
            }
        }
    }
}
int query(int r1,int c1,int r2,int c2)
{
    int k1=(int)log2((double)(r2-r1+1));
    int k2=(int)log2((double)(c2-c1+1));
    int a=dp[r1][c1][k1][k2];
    int b=dp[r1][c2+1-(1<<k2)][k1][k2];
    int c=dp[r2+1-(1<<k1)][c1][k1][k2];
    int d=dp[r2+1-(1<<k1)][c2+1-(1<<k2)][k1][k2];
    return max(max(a,b),max(c,d));
}
int ans;
bool f(int x,int y)
{
    if(a[x][y]==ans) return 1;
    return 0;
}
int main()
{
    while(~scanf("%d %d",&n,&m))
    {
        memset(dp,0,sizeof dp);
        memset(a,0,sizeof a);
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        prermq();
        int q;
        scanf("%d",&q);
        while(q--)
        {
            int r1,c1,r2,c2;
            scanf("%d %d %d %d",&r1,&c1,&r2,&c2);
            ans=query(r1,c1,r2,c2);
            printf("%d ",ans);
            if(f(r1,c1)||f(r2,c1)||f(r1,c2)||f(r2,c2))
            {
                printf("yes\n");
            }
            else printf("no\n");
        }
        
    }
}



YOLOv13改进策略【特征提取层】| CVPR-2024 PKI Module 获取多尺度纹理特征,适应尺度变化大的目标 PKI Module是。 阅读详情

相关推荐

CocosCreator视频播放黑屏?手把手教你封装VideoPlayer组件解决Web环境问题

本文针对Cocos Creator在Web环境下视频播放黑屏等常见问题,提供了一套工程化的VideoPlayer组件封装解决方案。文章深入剖析了浏览器自动播放策略、DOM样式隔离等核心挑战,并手把手教你实现一个健壮的管理器,涵盖兼容性处理、性能优化与内存管理,确保视频播放稳定流畅。

plum99的博客 598

HDU 2888:Check Corners(二维RMQ)

http://acm.hdu.edu.cn/showproblem.php?pid=2888 题意:给出一个n*m的矩阵,还有q个询问,对于每个询问有一对(x1,y1)和(x2,y2),求这个子矩阵中的最大值,和判断四个角有没有等于这个最大值的。 思路:二维RMQ模板题。注意内存卡的挺紧的。 1 #include <cstdio> 2 #include <cstr...

weixin_30556161的博客 164

以太网以及车载以太网概述

千兆网线和百兆网线区别 1、所谓的百兆网线其实就是 五类线 和超五类线 ,而千兆网线主要是指六类线 和超六类线 ,另外还有古老的十兆网线也就是指 四类线 和 三类线 等。 2、在使用上,其实千兆网线和百兆网线是没什么区别的,千兆网线完全兼容百兆网络。 3、百兆网线的线芯是8芯,但上传和下载只用到了其中的4根,而千兆网线需要完全用到8根。 4、另外在线芯的排布上,千兆网线的线芯中间有个十字形的塑料架,用来把四组8芯的线分开,这个百兆网线是没有的, 5、所有的网线在外皮上都有种类标识,CAT5 CAT

$好记性还是要多记录$ 4074

Check Corners(HDU-2888)

Problem Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all integer numbers ( 1 &lt;= i &lt;= m, 1 &lt;= j &lt;= n ). Now he selects some sub-matrices, hoping to find the...

Alex_McAvoy的博客 579

地心地固坐标系与北天东坐标系的转换

经过这一步旋转,x3轴和y3轴就处在过O3点的经度线所在的平面了,而且z3轴指向了东。将图3的坐标系旋转成图2的样子。这里需要多次旋转,每次以某个轴为对称轴进行旋转,对应的坐标变换参考。的原点在地心,Z轴指向北极点,X轴指向本初子午线与赤道的交点,Y轴指向符合右手定则,如下图所示。下面实现地心地固坐标系到北天东坐标系的转换,问题描述为:设一点。以y1轴为对称轴,顺时针旋转90°,得到图4的样子。,X轴指向北,Y轴指向天,Z轴指向东,如下图所示。因此,北天东坐标下的坐标为。点在图3坐标系下的坐标。

csdnqixiaoxin的博客 3555

31、MSP430FR2355时钟系统与低功耗模式解析

本文详细解析了MSP430FR2355的时钟系统和低功耗模式。首先介绍了时钟系统的组成,包括XT1振荡器、DCO、MODCLK、MCLK、SMCLK和ACLK的功能与配置方法。接着探讨了MSP430FR2355的五种低功耗模式及其配置要点,并分析了时钟系统与低功耗模式之间的协同关系。最后通过实际应用案例展示了如何在具体场景中优化系统功耗。文章旨在帮助开发者充分利用MSP430FR2355的时钟与低功耗特性,实现高性能、低功耗的嵌入式系统设计。

mars5的博客 194

HDU2888 Check Corners(二维线段树)

Check Corners Time Limit: 2000/10000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3599Accepted Submission(s): 1290 Problem Description Paul draw a big m*...

pxlsdz的博客 454

Isaac Lab & GR00T N1 入门教程(七)人形机器人推理与技能学习策略基准测试

本文介绍了IsaacLab设计的工业机器人操作评估系统,包含两项任务:螺母倾倒(成功率91%)和排气管分拣(成功率95%)。系统支持通过IsaacGR00TN1模型进行策略闭环评估,提供完整的开发环境配置指南(需Ubuntu22.04、CUDA12.8等环境),数据集下载方式(HuggingFace平台托管),以及模型微调流程。评估支持并行化测试(建议10-30个并行环境),并给出详细硬件配置建议(推荐RTX A6000 Ada显卡)。文档还包含常见问题解决方案,特别说明当前暂不支持Blackwell GP

2506_90492529的博客 1118

Check Corners 【HDU - 2888】【二维线段树】

题目链接   很多人写这道题都用的是二维RMQ,但是,我觉得这道题可以锻炼一下我二维线段树的思维,但是,无独有偶,这道题会卡一些二维线段树的模板,一开始我想也没想,直接敲了刚学的线段树,然后不停的RE,后来改了下,换成单点更新与区间更新二维线段树,还是不行TLE了,于是,就开始想,我们该如何把二维线段树双重区间写出来,然后,研究了下他的向下更新操作,我们不妨可以结合一下单点更新作出改进,譬如看向...

既然弱小,就只顾变强就是了 275

【Python计量】linearmodels面板数据回归(一)

我们以伍德里奇《计量经济学导论现代方法》的”第14章高级面板数据方法“的案例14.1为例,使用jtrain中的数据来进行固定效应估计。

mfsdmlove的博客 9275

21天学会基于 Linux 的 NPU 固件开发--2.2 固件加载流程:request_firmware() 深度解析

本文深度解析Linux内核中NPU固件加载流程,重点剖析request_firmware()机制。内容涵盖:1)内核态与用户态的交互机制,包括同步/异步加载方式;2)NPU固件的特殊格式与加载逻辑;3)调试技巧与安全验证方案;4)提供最小化固件加载器实验。文章揭示了从文件系统到硬件初始化的完整链路,探讨了大模型时代面临的性能挑战与优化方案,如零拷贝加载技术,并提出了版本兼容性、断电恢复等关键问题的思考方向。

amy_mhd的博客 59

hdu 2888(二维RMQ)

Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 858    Accepted Su

志当存高远 1024

【乐企】有关乐企能力测试接口对接-基础版(详细)

乐企能力测试接口对接详细代码以及步骤

九七的博客 7655

HDU 2888 Check Corners【二维RMQ】

题意:很简单就是求某一区间的最大值是不是在四个角落; 思路:因为矩阵是300*300的所以想到二维RMQ刚好内存也刚好卡; 二维RMQ初始化的时候要注意 当k=0时 ma[i][j][k][l]=max(ma[i][j][k][l-1],ma[i][j+(1 当k≠0时 ma[i][j][k][l]=max(ma[i][j][k-1][l],ma[i+(1 询问的

Mirai_Future 430

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

hdu 2888 Check Corners 二维rmq

这题考的细节比较多,wang了3次,有三个注意点 1、内存把握好 2、要初始化行,同时要初始化列 3、求最大值时,要考虑四个角,不能只考虑左上角和右下角 #include #include int num[305][305],d[301][301][9][9],n,m; int Max(int x,int y) { return x>y?x:y; } void init_r

u010690055的专栏 703

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

hdu 2888 Check Corners(二维rmq)

Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1374    Accepted Submission(s): 507 Problem Description Paul draw a

街角的花街糖 671

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

hdu2888—Check Corners(二维RMQ)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2888 Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2951    Accepted Subm

zhiyuanjiang的博客 315

HDU 2888 Check Corners(简单二维RMQ)

题意:给定一个n * m的矩阵,再给定q个询问,每次询问(r1,c1)为左上角,(r2,c2)为右下角的子矩形的最大值,并且判断该最大值是否出现在了这个子矩阵的4个顶角上? 思路:二维RMQ,不过要注意是无符号整数 #include #include #include using namespace std; const int MAXN =305; unsigned int val[

围巾的ACM博客 1018

HDU2888 Check Corners (二维RMQ)

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...

邵光亮的博客 277

hdu2888 Check Corners (二维RMQ,模板题)

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 m...

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 200

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

Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3602    Accepted Submission(s): 1291   Problem Description Paul draw a big m*n ma...

红点雷龙XL 297

hdu 2888 Check Corners (二维rmq模版)

/* 题意: (x1,y1)到(x2,y2)这个子矩阵中的四个角是否为子矩阵的最大值 二维rmq模版 */ # include # include # include # include using namespace std; const int N=305; int n,m; int dpmax[N][N][9][9];//2^9-1 int val[N][N]; void RMQ(

苍竹林 397

Hdu 2888 Check Corners (数据结构_二维RMQ)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2888 题目大意:给定一个n * m的矩阵,再给定q个询问,每次询问(r1,c1)为左上角,(r2,c2)为右下角的子矩形的最大值。 解题思路:很常规的二维RMQ查询最大值。第一次写二维rmq,现在来理下思路。

1028

Check Corners HDU - 2888(二维RMQ)

就是板题。。 查询子矩阵中最大的元素。。。然后看看是不是四个角落的 是就是yes 不是就是no 判断一下就好了 #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #inclu...

babing2770的博客 176

HDU-2888——Check Corners(二维RMQ)

题意:给你一个N*M的矩阵,询问一个子矩阵的最大值,并且判断子矩阵的四边是不是等于子矩阵的最大值 分析:这是一道显然的RMQ问题,没啥好说的,注意细节! #include #include #include #include #include #include #include #include #include #include #include #include #

shengtao96的专栏 552

HDU 2888 Check Corners 二维RMQ

Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1923    Accepted Submission(s): 683 Problem Description Paul draw a big

小人物的草稿本 788
上一篇: HDU 3486 Interviewe(RMQ+二分)
下一篇: NBUOJ 2383 泰拳之王(计数)
Mr_Treeeee
博客等级 码龄10年 38粉丝 551原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值