题目

代码
import java.util.Scanner;
public class Main {
static int N=1001;
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int XY[][] = new int[N][N];
int XZ[][] = new int[N][N];
int YZ[][] = 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();
XY[x][y]++;
XZ[x][z]++;
YZ[y][z]++;
if(XY[x][y]>=n) res++;
if(XZ[x][z]>=n) res++;
if(YZ[y][z]>=n) res++;
System.out.println(res);
}
}
}
tips
- 三维平面,直接拆成三个二维平面暴力
- 因为插入的砖块是1*1*N的,所以不用记录切割的奶酪块的位置,只有这一维度上的奶酪块都被切掉,才能放入一个砖块,所以只记录数量即可
- int res = 0;语句记得放在循坏外,脑子坏掉放到循坏里面,每一次都是满的奶酪,结果人家让求的是每一次。。。。