"BZOJ-1218" laser bomb prefixes and + enumerations

Source: Internet
Author: User

1218: [HNOI2003] Laser bomb time limit:10 Sec Memory limit:162 MB
submit:1778 solved:833
[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 Output1Hintsourcesolution

Noip2015day2t1 both visual sense

prefix and handle it, casually enumerate

Code
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespacestd;intRead () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9') {if(ch=='-') f=-1; Ch=GetChar ();}  while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}intn,r,maxx,maxy,ans,sum[5010][5010];intMain () {n=read (), r=read ();  for(intX,y,w,i=1; i<=n; i++) x=read () +1, Y=read () +1, W=read (), Maxx=max (X,maxx), Maxy=max (maxy,y), sum[x][y]=W;  for(intI=1; i<=5001; i++)         for(intj=1; j<=5001; J + +) Sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];  for(intk=0; i<=5001; i++)         for(intJ=r; j<=5001; J + +) ans=max (sum[i][j]-sum[i-r][j]-sum[i][j-r]+sum[i-r][j-R],ans); printf ("%d\n", ans); return 0;}

This JB question, the beginning of the hand of one of the 5001 dozen into 5000 has not been found, mdzz

Dcrusher always give me a water problem .

"BZOJ-1218" laser bomb prefixes and + enumerations

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.