AcWing 6122. 农夫约翰的奶酪块(蓝桥杯集训·每日一题2025)
在这里插入图片描述

  • 三维平面,直接拆成三个二维平面
  • 因为插入的砖块是11N的,所以不用记录切割的奶酪块的位置,只有这一维度上的奶酪块都被切掉,才能放入一个砖块,所以只记录数量即可
  • 每更新一次xyz,输出所有可能的方案数 记得每一次循环输出一次ans
import java.util.Scanner;
 
public class Main {
    static int N=1001;
    
    public static void main(String []args) {
        Scanner scan = new Scanner(System.in);
        int a[][] = new int[N][N];
        int b[][] = new int[N][N];
        int c[][] = new int[N][N];
        int n = scan.nextInt();
        int q = scan.nextInt();
        int res = 0;
        while(q-->0){
            int x = scan.nextInt();
            int y = scan.nextInt();
            int z = scan.nextInt();
            a[x][y]++;
            b[x][z]++;
            c[y][z]++;
            if(a[x][y]>=n) res++;
            if(b[x][z]>=n) res++;
            if(c[y][z]>=n) res++;
            //或if(++a[x][y]>=n) res++;
            //	if(++b[x][z]>=n) res++;
            //	if(++c[y][z]>=n) res++;
            System.out.println(res);
        }
 
    }
}

更多推荐