From fad1d98268321a9377ea88deb69d9f3468c3b816 Mon Sep 17 00:00:00 2001 From: alswnsp411 Date: Sun, 1 Dec 2024 21:40:11 +0900 Subject: [PATCH] =?UTF-8?q?24.12.01=20MinjuKim=20ps=20Simulation=2012100:?= =?UTF-8?q?=202048=20=EB=AC=B8=EC=A0=9C=20-=20=EC=83=81=ED=95=98=EC=A2=8C?= =?UTF-8?q?=EC=9A=B0=20=EC=9D=B4=EB=8F=99=20=EB=B0=A9=ED=96=A5=EC=9D=84=20?= =?UTF-8?q?=EA=B2=B0=EC=A0=95=ED=95=A0=20=EB=95=8C=204*4*4*4*4=20=EA=B0=80?= =?UTF-8?q?=EC=A7=80=EC=9D=98=20=EA=B2=BD=EC=9A=B0=EC=9D=98=20=EC=88=98?= =?UTF-8?q?=EB=A5=BC=20=EB=82=98=EB=A8=B8=EC=A7=80=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=B4=20=EB=AA=A8=EB=91=90=20=ED=83=90=EC=83=89?= =?UTF-8?q?=ED=96=88=EB=8B=A4.=20-=20up(),=20down(),=20left(),=20right()?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20=EB=82=98=EB=88=84?= =?UTF-8?q?=EC=96=B4=20=EA=B5=AC=ED=98=84=ED=96=88=EB=8A=94=EB=8D=B0=20?= =?UTF-8?q?=EA=B0=81=20=EC=9D=B4=EB=8F=99=EC=97=90=20=EB=8C=80=ED=95=B4=20?= =?UTF-8?q?=EB=B0=98=EB=B3=B5=EB=90=98=EB=8A=94=20=ED=8C=A8=ED=84=B4?= =?UTF-8?q?=EC=9D=84=20=EA=B3=B5=ED=86=B5=20=EB=A1=9C=EC=A7=81=EC=9D=84=20?= =?UTF-8?q?=EC=B6=94=EC=B6=9C=ED=95=B4=EB=B4=90=EC=95=BC=EA=B2=A0=EB=8B=A4?= =?UTF-8?q?..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MinJu/9week/src/Simulation12100.java | 178 +++++++++++++++++++++++++++ MinJu/9week/src/Simulation18808.java | 95 ++++++++++++++ 2 files changed, 273 insertions(+) create mode 100644 MinJu/9week/src/Simulation12100.java create mode 100644 MinJu/9week/src/Simulation18808.java diff --git a/MinJu/9week/src/Simulation12100.java b/MinJu/9week/src/Simulation12100.java new file mode 100644 index 0000000..626758e --- /dev/null +++ b/MinJu/9week/src/Simulation12100.java @@ -0,0 +1,178 @@ +import java.io.*; +import java.util.*; + +public class Simulation12100 { + static int n; + static int[][] board = new int[20][20]; + static int[][] mainboard = new int[20][20]; + static boolean[][] status = new boolean[20][20]; //합쳐진 상태 + static int maxblock=0; + + //최대 5번 이동해서 만들 수 있는 가장 큰 블록의 값 + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + n = Integer.parseInt(br.readLine()); + StringTokenizer st; + for (int i = 0; i < n; i++) { //2048 칸 채우기 + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < n; j++) { + mainboard[i][j] = Integer.parseInt(st.nextToken()); + } + } + + //상하좌우 이동을 5번하고 가장 큰 블록을 찾는다. 4*4*4*4*4 + int i = 0; + while (i < 1024) { + for (int j = 0; j < n; j++) { //이동할 보드 클론 + board[j] = mainboard[j].clone(); + } + + int t=i; + for (int j = 0; j <= 4; j++) { + int ti= t%4; + if (ti == 0) { + up(); + } + if (ti == 1) { + down(); + } + if (ti == 2) { + left(); + } + if (ti == 3) { + right(); + } + for (int l = 0; l < n; l++) { + Arrays.fill(status[l], false); //상태 행렬 초기화 + } + + t/=4; + } + + i++; + int max=0; + for (int j = 0; j < n; j++) { + for (int l = 0; l < n; l++) { + if(max= 0) { + if (board[temp][j] != 0) { + break; + } + temp--; + } + if(temp==i-1&& board[temp][j]!=board[i][j]) continue; //아무일도 일어나지 않는 경우 + + if (temp!=-1 && !status[temp][j] && board[temp][j] == board[i][j]) { //블록이 합쳐지는 경우 + board[temp][j] += board[i][j]; + status[temp][j] = true; + board[i][j] = 0; + continue; + } + + //블록이 합쳐지지 않는 경우 : 이동만 + board[temp + 1][j] = board[i][j]; + board[i][j] = 0; + } + } + } + } + + public static void down() { + for (int j = 0; j =0; i--) { //행 + if (board[i][j] != 0) { //블록에 숫자가 써있는 경우 + int temp = i +1; //가장 아래 숫자 블록 위치 + while (temp = 0) { + if (board[i][temp] != 0) { + break; + } + temp--; + } + if(temp==j-1&& board[i][temp]!=board[i][j]) continue; //아무일도 일어나지 않는 경우 + + if (temp!=-1 && !status[i][temp] && board[i][temp] == board[i][j]) { //블록이 합쳐지는 경우 + board[i][temp] += board[i][j]; + status[i][temp] = true; + board[i][j] = 0; + continue; + } + + //블록이 합쳐지지 않는 경우 : 이동만 + board[i][temp+1] = board[i][j]; + board[i][j] = 0; + } + } + } + } + + public static void right() { + for (int i = 0; i < n; i++) { //행 + for (int j = n-2; j >=0; j--) { //열 + if (board[i][j] != 0) { //블록에 숫자가 써있는 경우 + int temp = j + 1; //가장 오른쪽에 위치하는 숫자 블록 위치 + while (temp queue= new LinkedList<>(); //스티커 저장 배열 + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + n = Integer.parseInt(st.nextToken()); //노트북의 세로 길이 + m = Integer.parseInt(st.nextToken()); //가로 길이 + k = Integer.parseInt(st.nextToken()); //스티커의 개수 + + for (int i = 0; i < k; i++) { + st = new StringTokenizer(br.readLine()); + int r= Integer.parseInt(st.nextToken()); + int c= Integer.parseInt(st.nextToken()); + int[][] sticker= new int[r][c]; + for (int j = 0; j < r; j++) { + st = new StringTokenizer(br.readLine()); + for (int l = 0; l < c; l++) { + sticker[j][l]=Integer.parseInt(st.nextToken()); + } + } + queue.add(sticker); + } + + while (!queue.isEmpty()) { //차례대로 스티커 붙이기 + int[][] sticker = queue.poll(); + + boolean isCnt=false; + //90도씩 돌려서 네 번 반복 + for (int t = 0; t < 4; t++) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + isCnt=func(sticker, i, j); //스티커 대보기 + if(isCnt) { + func2(sticker, i, j); + break; + } + } + if(isCnt) break; + } + if(isCnt) break; + sticker = func3(sticker).clone(); //스티커 90도 회전 + } + } + + System.out.println(cnt); + } + + public static boolean func(int[][] sticker, int x, int y) { //sticker를 붙일 수 있는지 확인 + int r = sticker.length; + int c = sticker[0].length; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + if(x+i>=n || y+j>=m) return false; //범위 밖 + if(sticker[i][j]==1 && note[x+i][y+j]){ //스티커를 붙일 수 없다. + return false; + } + } + } + return true; + } + + public static void func2(int[][] sticker, int x, int y) { //sticker 붙이기 + int r = sticker.length; + int c = sticker[0].length; + + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + if(sticker[i][j]==1){ //스티커를 붙일 수 없다. + note[x+i][y+j]=true; + cnt++; + } + } + } + } + + public static int[][] func3(int[][] sticker) { + int r= sticker.length; + int c= sticker[0].length; + int[][] newSticker= new int[c][r]; + + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + newSticker[j][r-1-i] = sticker[i][j]; + } + } + return newSticker; + } +}