2023第十四届蓝桥杯Java省赛(棋盘)

134 阅读1分钟
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] arr = new int[m][4];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < 4; j++) {
                arr[i][j] = sc.nextInt() - 1;
            }
        }

        int[][] cntOpt = new int[n][n];
        for (int i = 0; i < m; i++) {
            int x1 = arr[i][0];
            int x2 = arr[i][2];
            int y1 = arr[i][1];
            int y2 = arr[i][3];

            for (int x = x1; x <= x2; x++) {
                for (int y = y1; y <= y2; y++) {
                    cntOpt[x][y]++;
                }
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (cntOpt[i][j] % 2 == 0) cntOpt[i][j] = 0;
                else cntOpt[i][j] = 1;
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(cntOpt[i][j]);
            }
            System.out.println();
        }
    }


}