本文最后更新于583 天前,其中的信息可能已经过时,如有错误请发送邮件到1739584917@qq.com
#include <iostream>
using namespace std;
int n, m;
int a[105][105], sum[105][105];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
}
}
//计算左上顶点(x1,y1)到右下顶点(x2,y2)矩形的面积
int ans = sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
}