思路:创建两个bool数组来模拟下落过程,一个存放面板状态,一个存放下落的格子。检测格子和面板对应位置是否同时为True,如果是则有冲突,不能继续下落,否则增加行号。为了统一处理,我们把面板最下面加一行True。
1 import java.util.*; 2 public class Main { 3 static boolean[][] board = new boolean[20][20]; 4 static boolean[][] block = new boolean[4][4]; 5 public static void main(String[] args) { 6 Scanner cin = new Scanner(System.in); 7 for (int i = 0; i < 15; i++) 8 for (int j = 0; j < 10; j++) 9 board[i][j] = cin.nextInt() == 1; 10 for (int i = 0; i < 10; i++) 11 board[15][i] = true; 12 for (int i = 0; i < 4; i++) 13 for (int j = 0; j < 4; j++) 14 block[i][j] = cin.nextInt() == 1; 15 int c = cin.nextInt(), r = 0; 16 c--; 17 while (check(r + 1, c)) 18 r++; 19 for (int i = 0; i < 4; i++) 20 for (int j = 0; j < 4; j++) 21 if (block[i][j]) 22 board[r + i][c + j] = true; 23 for (int i = 0; i < 15; i++) { 24 for (int j = 0; j < 9; j++) 25 System.out.print((board[i][j] ? 1 : 0) + " "); 26 System.out.println(board[i][9] ? 1 : 0); 27 } 28 } 29 static boolean check(int r, int c) { 30 for (int i = 0; i < 4; i++) 31 for (int j = 0; j < 4; j++) 32 if (board[r + i][c + j] && block[i][j]) 33 return false; 34 return true; 35 } 36 }
时间: 2024-12-10 13:54:49