Original title link: https: //www.acwing.com/problem/content/description/101/
A novel laser bombs that can destroy a side length R of all targets within the R square.
There are now on the map N N target, integer the X- i , the Y- i Xi, Yi represents the position of the target on the map, and each has a target value W i the Wi.
Laser bombs served by satellite positioning, but it has a disadvantage that its explosion range, i.e., the side length R sides of the square must be of the R and X , Y X, Y-axis.
If the target is located on the edge of the square blasting, the target will not be destroyed.
Seeking a bomb blew up on the map up to a total value of how much of the target.
Input Format
The first line of the input positive integer N N and R & lt R & lt, represents the number of objects on the side of the square, and the map data separated by spaces.
Next N N rows, each set of input data, each set of data comprises three integers X- I , the Y I , W is I Xi, Yi, the Wi, representing the target X X coordinate, Y Y coordinate and value data separated by a space.
Output Format
Output a positive integer representing up to blow up a bomb on the value of the total number of map objects.
data range
0≤R≤1e9
0<N≤10000 ,
0≤Xi,Yi≤5000
0≤Wi≤1000
Sample input:
2 1
0 0 1
1 1 1
Sample output:
1
求某点的前缀和:
s[i][j]=g[i-1][j]+g[i][j-1]-g[i-1][j-1]+g[i][j];
二维前缀和:
Red area is all part of the colored area minus the area of green plus yellow area (due to multi-cut)
AC代码:
#include<bits/stdc++.h> using namespace std; const int maxn=5050; int n1,r; int g[maxn][maxn]; int main(){ cin>>n1>>r; int x,y,w; int n=r,m=r; for(int i=0;i<n1;i++){ cin>>x>>y>>w; x ++ and ++ ; n=max(x,n); m=max(y,m); g[x][y]=w; } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ g[i][j]=g[i-1][j]+g[i][j-1]-g[i-1][j-1]+g[i][j]; } } int ans=0; int t; for(int i=r;i<=n;i++){ for(int j=r;j<=m;j++){ T = G [I] [J] -g [IR] [J] -g [I] [JR] + G [IR] [JR ]; // count is a side is (r-1) is square and, because without the edge years = max (year t); } } cout<<ans<<endl; }