[HNOI2003]激光炸弹

题目

Description
一种新型的激光炸弹,可以摧毁一个边长为R的正方形内的所有的目标。现在地图上有n(N<=10000)个目标,用整数Xi,Yi(其值在[0,5000])表示目标在地图上的位置,每个目标都有一个价值。激光炸弹的投放是通过卫星定位的,但其有一个缺点,就是其爆破范围,即那个边长为R的正方形的边必须和x,y轴平行。若目标位于爆破正方形的边上,该目标将不会被摧毁。
Input
输入文件的第一行为正整数n和正整数R,接下来的n行每行有3个正整数,分别表示xi,yi,vi
Output
输出文件仅有一个正整数,表示一颗炸弹最多能炸掉地图上总价值为多少的目标(结果不会超过32767)。
Sample Input
2 1
0 0 1
1 1 1
Sample Output
1

题解

哇!!省选题好难啊!!
emm 事实上这是一道非常非常水的省选题!
好吧,现在来说题解。
维护一个二维前缀和即可。
这么水的题还看题解

code

甩代码.jpg

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fup(i, a, b) for(int i = a; i <= b; ++i) 
#define fdown(i, a, b) for(int i = a; i >= b; --i)
#define pri_(k) printf("%d ", k)
#define pri(k) printf("----%d---\n", k)
const int maxn = 5e3 + 100;
const int inf = 0x3f3f3f3f;
typedef long long ull;

namespace millope {
    inline void kswap(int &a, int &b) { a ^= b ^= a ^= b; }
    inline int kmin(int a, int b) { return a > b ? b : a; }
    inline int kmax(int a, int b) { return a > b ? a : b; }
    inline int read() {
        int s = 0, w = 1;
        char ch = getchar();
        while (!isdigit(ch)) { if (ch == '-') w = -1; ch = getchar(); }
        while (isdigit(ch)) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
        return s * w;
    }
}
using namespace millope;
using namespace std;

int n;
int r;
int ans;
int a[maxn][maxn];
#define N 5001

int main() {
	n = read(); r = read();
	for (int x, y, w, i = 1; i <= n; ++i) {
		x = read(), y = read(), w = read();
		a[x + 1][y + 1] = w;
	}
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			a[i][j] += a[i - 1][j];
		}
	}
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			a[i][j] += a[i][j - 1];
		}
	}
	for (int i = r; i <= N; ++i) {
		for (int j = r; j <= N; ++j) {
			ans = max(ans, a[i][j] + a[i - r][j - r] - a[i - r][j] - a[i][j - r]);	
		}
	}
	printf("%d\n", ans);
	return 0;
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值