8 条题解
-
1廖浩宇 LV 6 @ 2023-10-22 18:25:33
#include <bits/stdc++.h> //liaohaoyu using namespace std; int s[1001][1001]; //本来想开114514的 int main() { int n, m, k; cin >> n >> m >> k; for(int i = 1;i <= n;i++) { for(int j = 1;j <= m;j++) { cin >> s[i][j]; s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + s[i][j]; } } for(int i = 1;i <= k;i++) { int x, x2, y, y2; cin >> x >> y >> x2 >> y2; cout << s[x2][y2] - s[x2][y-1] - s[x-1][y2] + s[x-1][y-1] << endl; } }
-
12023-4-30 14:46:43@
#include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> using namespace std; #define LL long long const int N = 1e6 + 10; const int INF = 0x3f3f3f3f; int n,m,k,a[1005][1005]; int main(){ cin >> n >> m >>k; for (int i=1; i<=n; i++){ for (int j=1; j<=m; j++){ cin >> a[i][j]; a[i][j]=a[i-1][j]+a[i][j-1]-a[i-1][j-1]+a[i][j]; } } while(k--){ int y1,y2,x1,x2; cin >> x1>>y1>>x2>>y2; cout<<a[x2][y2]-a[x2][y1-1]-a[x1-1][y2]+a[x1-1][y1-1]<<" "<<endl; } return 0; }
-
12023-3-12 15:48:29@
/********************************* all rights reserved. *********************************/ #include<bits/stdc++.h> using namespace std; int n,m,f[1005][1005],k,x1,x2; int y3,y2,x; int main() { cin>>n>>m>>k; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { cin>>x; f[i][j]=x+f[i-1][j]+f[i][j-1]-f[i-1][j-1]; } } while(k--) { cin>>x1>>y3>>x2>>y2; cout<<f[x2][y2]-f[x1-1][y2]-f[x2][y3-1]+f[x1-1][y3-1]<<"\n"; } return 0; }
-
12023-1-23 12:38:42@
#include<iostream> using namespace std; int a[1005][1005]; int main(){ int n,m,x; cin>>n>>m>>x; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; a[i][j]=a[i-1][j]+a[i][j-1]-a[i-1][j-1]+a[i][j]; } } for(int i=1;i<=x;i++){ int x1,x2,y1,y2; cin>>x1>>y1>>x2>>y2; cout<<a[x2][y2]-a[x2][y1-1]-a[x1-1][y2]+a[x1-1][y1-1]<<"\n"; } }
-
02024-7-24 11:26:40@
//#define int long long using namespace std; const int N = 1e3 +10; const int INF=0x3f3f3f; int n,m,z,sx,sy,ex,ey,a[N][N],b[N][N],d[N]; int main(){ cin>>n>>m>>z; for(int i = 1;i<=n;i++){ for(int j = 1;j<=m;j++){ cin>>a[i][j]; a[i][j] = a[i-1][j] + a[i][j-1] - a[i-1][j-1] + a[i][j]; } } for(int i = 1;i<=z;i++){ cin>>sx>>sy>>ex>>ey; cout<<a[ex][ey] - a[sx-1][ey] - a[ex][sy-1] + a[sx-1][sy-1]<<endl; } return 0; }
-
02024-5-21 17:21:32@
最简代码@man!
#include<bits/stdc++.h> using namespace std; long long n,m,k,a[10010][10010],s[10010][10010]; int main(){ cin>>n>>m>>k; 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]; } while(k--){ int i,j,p,q;cin>>i>>j>>p>>q;cout<<s[p][q]-s[p][j-1]-s[i-1][q]+s[i-1][j-1]<<endl; } return 0; }
-
-22021-12-18 19:34:06@
#include <iostream> #include <stdio.h> #include <string.h> #include <queue> #include <math.h> #include <vector> #include <algorithm> #include <iomanip> #include <stack> using namespace std; #define LL long long const int N =1e5+10; const int INF =0x3f3f3f3f; int a[1001][1001]; int main(){ int n,m,t,x1,y1,x2,y2; cin>>n>>m>>t; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1]; } } while(t--){ cin>>x1>>y1>>x2>>y2; cout<<a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1]<<endl; } return 0; }
-
-32022-9-26 16:24:09@
#include<iostream> using namespace std; int n,m,k,a[1005][1005],b[1005][1005],x1,x2,y1,y2; int main(){ cin>>n>>m>>k; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+a[i][j]; \\构造前缀和二维数组 } } for(int i=1;i<=k;i++){ cin>>x1>>y1>>x2>>y2; cout<<b[x2][y2]-b[x2][y1-1]-b[x1-1][y2]+b[x1-1][y1-1]<<endl;\\代入公式 } }
- 1
信息
- ID
- 1283
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 663
- 已通过
- 210
- 上传者