当前位置:网站首页>子矩阵的和
子矩阵的和
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;
}
}边栏推荐
- 2022 examination for safety production management personnel of hazardous chemical production units and new version of examination questions for safety production management personnel of hazardous chem
- Taiwan Xinchuang sss1700 latest Chinese specification | sss1700 latest Chinese specification | sss1700datasheet Chinese explanation
- EDP to LVDS conversion design circuit | EDP to LVDS adapter board circuit | capstone/cs5211 chip circuit schematic reference
- Gnuradio 3.9 using OOT custom module problem record
- Scalar / vector / matrix derivation method
- About how USRP sets the sampling frequency below the minimum sampling frequency reached by the hardware
- 2022 R1 fast opening pressure vessel operation test question bank and R1 fast opening pressure vessel operation free test questions
- 2022 operation certificate examination for main principals of hazardous chemical business units and main principals of hazardous chemical business units
- Overall introduction of the project
- Capstone/cs5210 chip | cs5210 design scheme | cs5210 design data
猜你喜欢

Gnuradio transmits video and displays it in real time using VLC

Guojingxin center "APEC investment +": some things about the Internet sector today | observation on stabilizing strategic industrial funds

Generic configuration legend

About snake equation (3)

2022 safety officer-a certificate free examination questions and safety officer-a certificate mock examination

qt--将程序打包--不要安装qt-可以直接运行

High quality USB sound card / audio chip sss1700 | sss1700 design 96 kHz 24 bit sampling rate USB headset microphone scheme | sss1700 Chinese design scheme explanation

2022 chemical automation control instrument examination summary and chemical automation control instrument simulation examination questions

Common effects of line chart

2、TD+Learning
随机推荐
Different methods for setting headers of different pages in word (the same for footer and page number)
2021 tea master (primary) examination materials and tea master (primary) simulation test questions
[loss function] entropy / relative entropy / cross entropy
正则表达式
3. Multi agent reinforcement learning
ROS 问题(topic types do not match、topic datatype/md5sum not match、msg xxx have changed. rerun cmake)
5. Discrete control and continuous control
Gnuradio 3.9 using OOT custom module problem record
2022 safety officer-b certificate examination question bank and safety officer-b certificate simulation test questions
Break algorithm --- map
Working principle of stm32gpio port
Kuntai ch7511b scheme design | ch7511b design EDP to LVDS data | pin to pin replaces ch7511b circuit design
USB type-C mobile phone projection scheme | USB type-C docking station scheme | TV / projector type-C converter scheme | ag9300ag9310ag9320
Euler Lagrange equation
Leetcode notes No.21
Ag9310 design USB type C to hdmi+u2+5v slow charging scheme design | ag9310 expansion dock scheme circuit | type-C dongle design data
common commands
Guojingxin center "friendship and righteousness" - the meta universe based on friendship and friendship, and the parallel of "honguniverse"
Smart agricultural technology framework
Cs5261type-c to HDMI alternative ag9310 | ag9310 alternative