1218: [HNOI2003] Laser bomb time limit: ten Sec Memory Limit: 162 MB
Submit: 1221 Solved: 581
[Submit] [Status] [Discuss] Description
A new type of laser bomb that can destroy all the targets within a square with a side length of R. There are now N (n<=10000) targets on the map, with an integer xi,yi (whose value in [0,5000]) represents the position of the target on the map, each of which has a value. Laser bombs are placed through satellite positioning, but there is a drawback, is its scope of blasting, that is, the side of the R-side of the square must be parallel to the X, Y axis. If the target is on the edge of the blasting square, the target will not be destroyed. 0
Input
The first behavior of the input file is a positive integer n and a positive integer r, and the next n rows have 3 positive integers per line, respectively, representing
Output
The output file has only a positive integer, which means that a bomb can blow up a target with a maximum amount of value on the map (no more than 32767 results).
Sample Input2 1
0 0 1
1 1 1Sample Output1HINT
Source
Dp
Prefixes and + violence.
Maintain the i,j of the rectangle in the lower right corner, and then the violent enumeration is placed in each position of the resulting.
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include < cstdlib> #include <cmath> #define M 5001using namespace Std;int n,r,s[m+5][m+5];int main () { scanf ("%d%d", &N,&R); for (int i=1;i<=n;i++) {int x,y,v;scanf ("%d%d%d", &x,&y,&v); x++,y++;s[x][y]+=v;} for (int i=1;i<=m;i++) for (int j=1;j<=m;j++) s[i][j]+=s[i][j-1];for (int. i=1;i<=m;i++) for (int j=1;j<=m;j++ ) s[i][j]+=s[i-1][j];int ans=0;for (int i=r;i<=m;i++) for (int j=r;j<=m;j++) Ans=max (ans,s[i][j]-s[i][j-r]-s[i-r ][j]+s[i-r][j-r]); Cout<<ans<<endl;return 0;}
"Bzoj 1218" [HNOI2003] Laser bomb