当前位置:网站首页>子矩阵的和
子矩阵的和
2022-07-07 23:33:00 【三三木木七】
输入一个 n行 m 列的整数矩阵,再输入 q个询问,每个询问包含四个整数 x1,y1,x2,y2表示一个子矩阵的左上角坐标和右下角坐标。
对于每个询问输出子矩阵中所有数的和。
理解:

代码描述:

代码:
#include<iostream>
using namespace std;
const int N=1010;
int n,m,q;
int a[N][N],s[N][N];
int main()
{
cin>>n>>m>>q;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];
}
}
//查
int x1,y1,x2,y2;
for(int i=0;i<q;i++)
{
cin>>x1>>y1>>x2>>y2;
cout<<(s[x2][y2]-s[x2][y1-1]-s[x1-1][y2]+s[x1-1][y1-1])<<endl;
}
}边栏推荐
- Matlab method is good~
- Understanding of maximum likelihood estimation
- break algorithm---刷题map
- Design method and reference circuit of type C to hdmi+ PD + BB + usb3.1 hub (rj45/cf/tf/ sd/ multi port usb3.1 type-A) multifunctional expansion dock
- Leetcode notes No.7
- 3、多智能体强化学习
- 5、離散控制與連續控制
- Usage of xcolor color in latex
- Cs5212an design display to VGA HD adapter products | display to VGA Hd 1080p adapter products
- Deep learning website
猜你喜欢

2022 refrigeration and air conditioning equipment operation examination questions and refrigeration and air conditioning equipment operation examination skills

写一个纯手写的qt的hello world

Qt - - Packaging Programs - - Don't install Qt - can run directly

Ag9310 same function alternative | cs5261 replaces ag9310type-c to HDMI single switch screen alternative | low BOM replaces ag9310 design

Write a pure handwritten QT Hello World

2、TD+Learning

qt-使用自带的应用框架建立--hello world--使用min GW 32bit

从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值

Scheme selection and scheme design of multifunctional docking station for type C to VGA HDMI audio and video launched by ange in Taiwan | scheme selection and scheme explanation of usb-c to VGA HDMI c

4. Strategic Learning
随机推荐
2022 tea master (intermediate) examination questions and tea master (intermediate) examination skills
The persistence mode of redis - RDB and AOF persistence mechanisms
qt--將程序打包--不要安裝qt-可以直接運行
写一个纯手写的qt的hello world
Micro rabbit gets a field of API interface JSON
2021 Shanghai safety officer C certificate examination registration and analysis of Shanghai safety officer C certificate search
[loss function] entropy / relative entropy / cross entropy
Probability distribution
Working principle of stm32gpio port
Problems of font legend and time scale display of MATLAB drawing coordinate axis
ROS 问题(topic types do not match、topic datatype/md5sum not match、msg xxx have changed. rerun cmake)
Gnuradio 3.9 using OOT custom module problem record
Talk about smart Park
Apt get error
Getting started STM32 -- how to learn stm32
The difference between distribution function and probability density function of random variables
2021-03-14 - play with generics
Redis 主从复制
COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况----几何模型的建立
Content of one frame