0分
查看原帖
0分
749028
QAQ5楼主2024/12/27 18:30
import java.util.Scanner;

public class Main {
    static boolean[][] rect;

    public static void main(String[] args) {
        int n/*区域的大小*/, m/*火把的数量*/, k/*萤石的数量*/;
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        k = scanner.nextInt();
        //上半火把,下半萤石
        Position[] torchPoses/*学不会英语,缩写pos的复数是加es吗*/ = new Position[m];
        for (int count = 0; count < m; count++) {
            torchPoses[count] = new Position(scanner.nextInt(), scanner.nextInt());
        }
        Position[] fluoritePoses = new Position[k];//萤石为零,怎么省去这个声明
        for (int count = 0; count < k; count++) {
            fluoritePoses[count] = new Position(scanner.nextInt(), scanner.nextInt());
        }
        rect = new boolean[n][n];
        for (int i = 0; i < n; i++) {
            for (int i1 = 0; i1 < n; i1++) {
                rect[i][i1] = false;
            }
        }
        /*
        |暗|暗| 光 |暗|暗|
        |暗|光| 光 |光|暗|
        |光|光|火把|光|光|火把=光
        |暗|光| 光 |光|暗|
        |暗|暗| 光 |暗|暗|
         */
        boolean[][] torchLighting = new boolean[][]{
                {false, false, true, false, false},
                {false, true, true, true, false},
                {true, true, true, true, true},
                {false, true, true, true, false},
                {false, false, true, false, false}
        };//这是先y后x,正常坐标格式是(x,y)
        torchLighting = swapXY(torchLighting);
        Illuminant illuminantTorch = new Illuminant(torchLighting, rect, n);
        for (Position torchPos : torchPoses) {
            illuminantTorch.put(torchPos.x, torchPos.y);
        }
        /*
        |光|光| 光 |光|光|
        |光|光| 光 |光|光|
        |光|光|萤石|光|光|
        |光|光| 光 |光|光|
        |光|光| 光 |光|光|
         */
        boolean[][] fluoriteLighting = new boolean[][]{
                {true, true, true, true, true},
                {true, true, true, true, true},
                {true, true, true, true, true},
                {true, true, true, true, true},
                {true, true, true, true, true}
        };
        Illuminant illuminantFluorite = new Illuminant(fluoriteLighting, rect, n);
        for (Position fluoritePos : fluoritePoses) {
            illuminantFluorite.put(fluoritePos.x, fluoritePos.y);
        }
        //统计暗点
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (!rect[i][j]) count++;
            }
        }
        System.out.println(count / 2);
    }

    static boolean[][] swapXY(boolean[][] old) {
        int rowLen = old[0].length, colLen = old.length;
        boolean[][] NEW/*关键字碍事*/ = new boolean[rowLen][colLen];
        for (int x = 0; x < rowLen; x++) {
            for (int y = 0; y < colLen; y++) {
                NEW[x][y] = old[y][x];
            }
        }
        return NEW;
    }
}

class Illuminant {
    boolean[][] source, rect;
    int rowLen, colLen, rectSize;

    Illuminant(boolean[][] source, boolean[][] rect, int rectSize) {
        rowLen = source.length;
        colLen = source[0].length;
        this.source = source;
        this.rect = rect;
        this.rectSize = rectSize;
    }

    void put(int X, int Y) {
        int leftTopX = X - rowLen / 2, leftTopY = Y - colLen / 2;
        for (int rectY = leftTopY, sourceY = 0, countRow = 0; countRow < colLen; countRow++, sourceY++) {
            for (int rectX = leftTopX, sourceX = 0, countCol = 0; countCol < rowLen; countCol++, sourceX++) {
                if (in(rectX, rectY)) {
                    rect[rectX][rectY] = true;
                }
            }
        }
    }

    boolean in(int x, int y) {
        if (x < 0 || x >= rectSize || y < 0 || y >= rectSize)
            return false;
        return true;
    }
}

class Position {
    int x;

    public Position(int x, int y) {
        this.x = x;
        this.y = y;
    }

    int y;
}
2024/12/27 18:30
加载中...