Luo Gu P2280 [HNOI2003] laser bombs

Luo Gu P2280 [HNOI2003] laser bombs

topic:

  • There are pictures, transfer link

answer:

  • Prefix and two-dimensional.
  • Fraud seems to look a segment tree / violence?
  • The first difficulty is the first topic that is not located on the edge of the goal square blasting. How to solve this problem. In fact, you can put the coordinates of each target to a translation of the upper right corner.
  • For example, (0, 0) and (1, 1), the original sum (1, 1) is 2 (does not meet the meaning of the questions); after translation into a (1, 1) and (2, 2), sum (1, 1) becomes 1, it is still on.
  • The second difficulty is the topic that bomb is a square, so in order to (i, j) to the upper right corner of the answer is not a simple sum (i, j) = sum (i - 1, j) + sum (i, j - 1 ) - sum (i - 1, j - 1) a. After updating, but the sum, taking each ans max, as follows ↓
    • ans = max(ans, sum(i, j) - sum(i - r, j) - sum(i, j - r)+ sum(i - r, j - r))
    • So that we can take to ensure the ans is (i, j) to the upper right corner of the square (strongly recommended drawing understand)
#include <iostream>
#include <cstdio>
#define maxn 5005
using namespace std;

int n, r, ans;
int sum[maxn][maxn];

int main()
{
    cin >> n >> r;
    for(int i = 1; i <= n; i++)
    {
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z);
        sum[x + 1][y + 1] = z;
    }
    for(int i = 1; i <= 5000; i++)
        for(int j = 1; j <= 5000; j++)
            sum[i][j] += (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1]); 
    for(int i = r; i <= 5000; i++)
        for(int j = r; j <= 5000; j++)
            ans = max(ans, sum[i][j] - sum[i - r][j] - sum[i][j - r] + sum[i - r][j - r]);
    cout << ans;
    return 0;   
}

Guess you like

Origin www.cnblogs.com/BigYellowDog/p/11203149.html