当前位置:网站首页>子矩阵的和
子矩阵的和
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;
}
}
边栏推荐
- Working principle of stm32gpio port
- 写一个纯手写的qt的hello world
- General configuration tooltip
- Blue Bridge Cup embedded (F103) -1 STM32 clock operation and led operation method
- Gnuradio operation error: error thread [thread per block [12]: < block OFDM_ cyclic_ prefixer(8)>]: Buffer too small
- 2、TD+Learning
- NPM internal split module
- Redis master-slave replication
- Kaptcha generates verification code on Web page
- Ag9310meq ag9310mfq angle two USB type C to HDMI audio and video data conversion function chips parameter difference and design circuit reference
猜你喜欢
4、策略學習
Common configurations in rectangular coordinate system
Transportation, new infrastructure and smart highway
4. Strategic Learning
2022 refrigeration and air conditioning equipment operation examination questions and refrigeration and air conditioning equipment operation examination skills
General configuration title
Redis集群
3、多智能体强化学习
2022 tea master (intermediate) examination questions and tea master (intermediate) examination skills
The beauty of Mathematics -- the principle of fine Fourier transform
随机推荐
NPDP在国内有认可度吗?看一看就明白了!
Use "recombined netlist" to automatically activate eco "APR netlist"
Is it safe to open an account on your mobile phone for small amount of stock speculation?
Different methods for setting headers of different pages in word (the same for footer and page number)
如果时间是条河
The examination contents of the third batch of Guangdong Provincial Safety Officer a certificate (main person in charge) in 2021 and the free examination questions of the third batch of Guangdong Prov
Blue Bridge Cup embedded (F103) -1 STM32 clock operation and led operation method
HDMI to VGA acquisition HD adapter scheme | HDMI to VGA 1080p audio and video converter scheme | cs5210 scheme design explanation
2021 Shanghai safety officer C certificate examination registration and analysis of Shanghai safety officer C certificate search
ROS 问题(topic types do not match、topic datatype/md5sum not match、msg xxx have changed. rerun cmake)
2022 safety officer-c certificate examination summary and safety officer-c certificate reexamination examination
5. Discrete control and continuous control
Ag9310 design USB type C to hdmi+u2+5v slow charging scheme design | ag9310 expansion dock scheme circuit | type-C dongle design data
Gnuradio3.9.4 create OOT module instances
Application of state mode in JSF source code
Understanding of sidelobe cancellation
Cs5261type-c to HDMI alternative ag9310 | ag9310 alternative
common commands
2021-03-06 - play with the application of reflection in the framework
redis的持久化方式-RDB和AOF 两种持久化机制