您的位置:首页 > 其它

BZOJ 1218 HNOI 2003 激光炸弹 模拟

2014-11-21 17:47 435 查看
题目大意:见NOIP2014 Day2T1

CODE:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAX 5110
using namespace std;

int cnt,range;
int sum[MAX][MAX];

inline int Calc(int x,int y)
{
return sum[x + range][y + range] - sum[x - 1][y + range] - sum[x + range][y - 1] + sum[x - 1][y - 1];
}

int main()
{
cin >> cnt >> range;
--range;
for(int x,y,z,i = 1; i <= cnt; ++i) {
scanf("%d%d%d",&x,&y,&z);
sum[x + 1][y + 1] += z;
}
for(int i = 1; i <= 5010; ++i)
for(int j = 1; j <= 5010; ++j)
sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
int ans = 0;
for(int i = 1; i <= 5001 - range; ++i)
for(int j = 1; j <= 5001 - range; ++j)
ans = max(ans,Calc(i,j));
cout << ans << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息