D e s c r i p t i o n Description Description
给定一个 n ∗ m 的矩阵 A,对其进行 q 次询问:以 (x1, y1) 为左上角,(x2, y2) 为右下角的子矩
阵中,所有元素的最大值。
I n p u t Input Input
第一行包含三个整数 n,m 和 q。
之后 n 行每行包含 m 个整数 Ai,j。
之后 q 行每行包含四个整数 x1,y1,x2 和 y2。
O u t p u t Output Output
共 q 行包含一个整数 ans,表示子矩阵中所有元素的最大值。
S a m p l e Sample Sample I n p u t Input Input
3 3 2
1 2 3
1 2 3
2 3 1
1 1 2 2
2 2 3 3
S a m p l e Sample Sample O u t p u t Output Output
2
3
E x p l a i n Explain Explain
对于 100% 的数据:n, m, q ≤ 100
T r a i n Train Train o f of of T h o u g h t Thought Thought
读入完后,直接暴力模拟就好了
C o d e Code Code
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int n,m,a[101][101],q,maxx,ans;
int work(int x1,int y1,int x2,int y2)
{
maxx=0;
for (int i=x1; i<=x2; ++i)
for (int j=y1; j<=y2; ++j)
maxx=max(maxx,a[i][j]);//求最大值
return maxx;
}
int main()
{
scanf("%d%d%d",&n,&m,&q);
for (int i=1; i<=n; ++i)
for (int j=1; j<=m; ++j)
scanf("%d",&a[i][j]);
for (int i=1; i<=q; ++i)
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
ans=work(x1,y1,x2,y2);
printf("%d\n",ans);
}
}