6 5 2 1
4 3 2
3 2 1 2 5
1 2 4 1 1
3 3 3 1 2
4 43 1 1 5
5 2 2 2 4
1 1 3 1 5
16
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1050, M = 1e6 + 10;
int m, n, k, g;
int a[N][N], b[N][N];
int d[M][3];
//差分函数
void insert(int x1, int y1, int x2, int y2, int c){
b[x1][y1] += c;
b[x1][y2 + 1] -= c;
b[x2 + 1][y1] -= c;
b[x2 + 1][y2 + 1] += c;
}
int main(){
cin >> m >> n >> k >> g;
while (g -- ){
int x, y, r;
cin >> x >> y >> r;
insert(x - r, y - r, x + r, y + r, -k);//攻击,减去攻击范围内怪兽的生命值,k要输入负值
}
for (int i = 1; i <= m; i ++ )
for (int j = 1; j <= n; j ++ )
cin >> a[i][j], insert(i, j, i, j, a[i][j]);//将怪兽生命值插进去
for (int i = 1; i <= m; i ++ )
for (int j = 1; j <= n; j ++ )
a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1] + b[i][j];
int cnt = 0;
for (int i = 1; i <= m; i ++ ){
for (int j = 1; j <= n; j ++ ){
if (a[i][j] > 0) cnt ++;//如果怪兽生命值大于零,怪兽活着,要计数
}
}
cout << cnt << endl;
return 0;
}
原文:https://www.cnblogs.com/Iamcookieandyou/p/13232904.html