I Liked Matrix!【模拟】

Description–

给定一个 n ∗ m 的矩阵 A,对其进行 q 次询问:以 (x1, y1) 为左上角,(x2, y2) 为右下角的子矩
阵中,所有元素的最大值。


Input–

第一行包含三个整数 n,m 和 q。
之后 n 行每行包含 m 个整数 Ai,j。
之后 q 行每行包含四个整数 x1,y1,x2 和 y2。

Output–

共 q 行包含一个整数 ans,表示子矩阵中所有元素的最大值。


Sample Input–

3 3 2
1 2 3
1 2 3
2 3 1
1 1 2 2
2 2 3 3

Sample Output–

2
3


说明–

对于 100% 的数据:n, m, q ≤ 100


代码–

#include<iostream>
#include<cstdio>
using namespace std;
int n,m,q,x1,x2,y1,y2,ans,a[105][105];
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 k=1;k<=q;++k)
	{
		ans=0;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		for (int i=x1;i<=x2;++i)
		  for (int j=y1;j<=y2;++j)
		    ans=max(ans,a[i][j]);
		printf("%d\n",ans);
	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43654542/article/details/90698814