【暴力】I Liked Matrix!

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);
	 }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值