这是什么神奇的问题啊。
查看原帖
这是什么神奇的问题啊。
921508
r27153733楼主2023/1/11 23:25
import java.io.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Scanner;

public class Main {
    //static Scanner sc = new Scanner(System.in);
    static StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    //static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    public static int nextInt() throws Exception{
        cin.nextToken();
        return (int) cin.nval;
    }

    public static void main(String[] args) throws Exception {
        int n = nextInt();
        int r = nextInt();

        short[][] v = new short[5002][5002];
        for (int i = 0; i < n; i++) {
            v[nextInt() + 1][nextInt() + 1] = (short) nextInt();
        }

        for (int i = 1; i <= 5001; i++) {
            for (int j = 1; j <= 5001; j++) {
                v[i][j] += v[i - 1][j] + v[i][j - 1] - v[i - 1][j - 1];

            }
        }
        int res = 0;
        for (int i = r; i <= 5001; i++) {
            for (int j = r; j <= 5001; j++) {
                int t = v[i][j] - v[i - r][j] - v[i][j - r] + v[i - r][j - r];
                res = Math.max(t, res);
            }
        }
        out.println(res);
        out.flush();
    }


}

Unaccepted 55 wa 5 6 8 9 10

import java.io.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Scanner;

public class Main {
    //static Scanner sc = new Scanner(System.in);
    static StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    //static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    public static int nextInt() throws Exception{
        cin.nextToken();
        return (int) cin.nval;
    }

    public static void main(String[] args) throws Exception {
        int n = nextInt();
        int r = nextInt();

        short[][] v = new short[5002][5002];
        for (int i = 0; i < n; i++) {
            v[nextInt() + 1][nextInt() + 1] = (short) nextInt();
        }

        for (int i = 1; i <= 5001; i++) {
            for (int j = 1; j <= 5001; j++) {
                v[i][j] += v[i - 1][j] + v[i][j - 1] - v[i - 1][j - 1];

            }
        }
        short res = 0;
        for (int i = r; i <= 5001; i++) {
            for (int j = r; j <= 5001; j++) {
                short t = (short) (v[i][j] - v[i - r][j] - v[i][j - r] + v[i - r][j - r]);
                res = (short) Math.max(t, res);
            }
        }
        out.println(res);
        out.flush();
    }


}

Accepted 100

[bxd@arch Desktop]$ diff /home/bxd/Desktop/j.txt  /home/bxd/Desktop/j1.txt 
32c32
<         int res = 0;
---
>         short res = 0;
35,36c35,36
<                 int t = v[i][j] - v[i - r][j] - v[i][j - r] + v[i - r][j - r];
<                 res = Math.max(t, res);
---
>                 short t = (short) (v[i][j] - v[i - r][j] - v[i][j - r] + v[i - r][j - r]);
>                 res = (short) Math.max(t, res);

这是为什么啊!!!!

2023/1/11 23:25
加载中...