From ecebf54414c06b72c398836c519d4c8bc21c0008 Mon Sep 17 00:00:00 2001 From: yess98 <52556037+yess98@users.noreply.github.com> Date: Wed, 29 Dec 2021 23:21:06 +0900 Subject: [PATCH] =?UTF-8?q?[=EC=96=91=EC=9D=80=EC=84=9C]=20=EC=9B=80?= =?UTF-8?q?=EC=A7=81=EC=9D=B4=EB=8A=94=20=EB=AF=B8=EB=A1=9C=20=ED=83=88?= =?UTF-8?q?=EC=B6=9C=20(O)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yess.java" | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 "solution/BOJ_16954_\354\233\200\354\247\201\354\235\264\353\212\224-\353\257\270\353\241\234-\352\265\254\355\225\230\352\270\260/yess.java" diff --git "a/solution/BOJ_16954_\354\233\200\354\247\201\354\235\264\353\212\224-\353\257\270\353\241\234-\352\265\254\355\225\230\352\270\260/yess.java" "b/solution/BOJ_16954_\354\233\200\354\247\201\354\235\264\353\212\224-\353\257\270\353\241\234-\352\265\254\355\225\230\352\270\260/yess.java" new file mode 100644 index 0000000..f620c27 --- /dev/null +++ "b/solution/BOJ_16954_\354\233\200\354\247\201\354\235\264\353\212\224-\353\257\270\353\241\234-\352\265\254\355\225\230\352\270\260/yess.java" @@ -0,0 +1,82 @@ +``` +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Queue; + +public class Main { + static char [][] map; + static Queue queue = new ArrayDeque(); + static int [] dx = {1,1,-1,-1,0,0,1,-1,0}; + static int [] dy = {1,-1,-1,1,1,-1,0,0,0}; + static boolean check[][]; + static boolean flag = false; + static boolean flag2 = false; + + public static void main(String [] args) throws IOException { + BufferedReader br = new BufferedReader (new InputStreamReader(System.in)); + map = new char[8][8]; + check = new boolean [8][8]; + for(int i = 0 ; i < map.length; i ++ ) { + String s = br.readLine(); + for(int j = 0 ; j < map[i].length; j ++) { + map[i][j] = s.charAt(j); + } + } + queue.add(new int[] {7,0}); + while (true ) { + moveCharacter(); + if (flag == true ) break; + if (flag2 == true ) break; + moveBlock(); + //print(); + } + if (flag) System.out.println(1); + else if (flag2) System.out.println(0); + } + static void print() { + for(int i = 0 ; i < map.length; i ++) { + for(int j = 0 ; j < map[0].length; j ++) { + System.out.print(map[i][j] + " "); + } + System.out.println(); + } + System.out.println(); + } + static void moveBlock() { + for(int j = 0 ; j < 8 ; j ++) { + for(int i = 7 ; i >= 0 ; i --) { + if (i == 7 && map[i][j] == '#') map[i][j] = '.'; + else if (i != 7 && map[i][j] == '#') { + map[i][j] = '.'; + map[i + 1][j] = '#'; + } + } + } + } + static void moveCharacter() { + int size = queue.size(); + for(int i = 0 ; i < size; i ++) { + int [] temp = queue.poll(); + if (map[temp[0]][temp[1]] == '#') continue; + if (temp[0] == 0 && temp[1] == 7) { + flag = true; + return ; + } + for(int d = 0 ; d < dx.length; d ++ ) { + int nx = temp[0] + dx[d]; + int ny = temp[1] + dy[d]; + if (nx < 0 || nx >= 8 || ny < 0 || ny >= 8) continue; + if (map[nx][ny] == '#') continue; + queue.add(new int[] {nx,ny}); + } + } + if (queue.isEmpty()) { + flag2 = true; + return ; + } + } +} + +```