"Bzoj 1218" [HNOI2003] Laser bomb

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.