AcWing 99. 【java】激光炸弹
原题链接
简单
作者:
tt2767
,
2019-12-14 00:41:59
,
所有人可见
,
阅读 885
// map[x+1][y+1] = w; 也能过。。。。。
import java.util.*;
public class Main{
void run(){
int n = jin.nextInt();
int r = jin.nextInt();
int row = 5000;
int col = 5000;
for (int i = 0 ;i < n ; i++){
int x = jin.nextInt();
int y = jin.nextInt();
int w = jin.nextInt();
map[x+1][y+1] += w;
row = Math.max(row, x+1);
col = Math.max(col, y+1);
}
int res = 0;
for (int i = 1 ; i <= row; i++){
for (int j = 1 ; j <= col ;j++){
map[i][j] += map[i-1][j] + map[i][j-1] - map[i-1][j-1];
}
}
for (int i = r ; i <= row ; i++){
for (int j = r ; j <= col; j++){
res = Math.max(res, map[i][j] - map[i-r][j] - map[i][j-r] + map[i-r][j-r] );
}
}
System.out.println(res);
}
int[][] map = new int[5002][5002];
private Scanner jin = new Scanner(System.in);
public static void main(String[] args) throws Exception {new Main().run();}
}
需要考虑特殊情况(爆炸范围超过地图面积),修改如下:
if(r > Math.min(row,col)){
System.out.println(map[row][col]);
}else{
System.out.println(res);
}