Algorithm/baekjoon 126

구슬 탈출

📍 문제 설명 💡 접근 구슬이 동시에 움직여야하고 제약 사항이 꽤 있었기때문에 많이 까다로운 문제였다. 두 구슬의 방문여부를 각각 체크 해주기위해서 4차원 배열을 사용해야 했다. 1.파란 구슬과 빨간 구슬을 동시에 기울이고 2.상하좌우로 기울이는데, 다음칸이 벽이 아니고 현재 칸이 구멍이 아니라면 계속 움직인다. 3.구슬이 같은 칸에 있을 경우에는 뒤에서 온 구슬을 먼저온 구슬 뒤에 배치시킨다. 👩‍💻 코드 import java.util.*; public class Main { static int n, m, h, k, answer,cnt, max, L, R, C; static char[][] board, dis; static boolean[][][][] visited; static int[] ch,pm,..

Algorithm/baekjoon 2022.01.22

안전영역

📍 문제 설명 💡 접근 다 잠기지 않는 경우부터 다 잠기는 경우까지 해당 높이에 따라 안전 영역 계산해주면 되는 문제였다. 👩‍💻 코드 import java.util.*; public class Main { static int n, m, h, k, answer,cnt, max; static int[][] board, dis, clone; static boolean[][] visited; static int[] ch,pm, combi; static boolean flag = true; static int[] dx = {-1,1,0,0}; static int[] dy = {0,0,-1,1}; public static void main(String[] args) { Main T = new Main(); Sca..

Algorithm/baekjoon 2022.01.21

늑대와 양

📍 문제 설명 💡 접근 예제 출력이 그렇게 안나와있어서 늑대가 상하좌우로 무한정 이동할 수 있을거라고 생각했는데, 그냥 늑대 상하좌우로 울타리 쳐주면 되는 문제였다. 👩‍💻 코드 import java.util.*; public class Main { static int n, m, h, k, answer,cnt; static char[][] board,dis; static int[] ch,pm, combi; static boolean[] visited; static boolean flag = true; static int[] dx = {-1,1,0,0}; static int[] dy = {0,0,-1,1}; public static void main(String[] args) { Main T = new M..

Algorithm/baekjoon 2022.01.21

사다리 조작

📍 문제 설명 💡 접근 문제 이해하는데 시간이 꽤나 소요됐다. 가로선을 0~3번까지 추가하여 모든 지점에 대해서 가로선을 만들어 보는 완전탐색 & 백트래킹 문제 였다. 재귀 호출시 1,1 x,y 지점 모두 가능하나 i,j라고 했을땐 오답이 나온다. ex) 추가해야할 가로선 갯수 2 i = 1, j = 3이라고 하면 1,3 1,4 가로선 설치가능 여부 확인 부 2,1로 가는게 아니라 2,3 2,4 를 확인하기 때문에! 👩‍💻 코드 import java.util.*; public class Main { static int n, m, h, k, answer; static int[][] board,dis; static int[] ch,pm, combi; static boolean[] visited; static..

Algorithm/baekjoon 2022.01.21

스타트링크

📍 문제 설명 💡 접근 전형적인 bfs 문제였다. boolean[]으로 방문여부처리해도 되지만 int[]으로 거리기록해서 구해도 된다. 👩‍💻 코드 import java.util.*; public class Main { static int n, m, k; static int[][] board,dis; static int[] ch,pm, combi; static boolean[] visited; static int[] dx = {-1,1,0,0}; static int[] dy = {0,0,-1,1}; public static void main(String[] args) { Main T = new Main(); Scanner kb = new Scanner(System.in); int f = kb.nextIn..

Algorithm/baekjoon 2022.01.19

DSLR

📍 문제 설명 💡 접근 연산의 최소 횟수를 구하면 되는 문제로 BFS를 이용하면 되는 문제였다. 다른 연산으로 덮어씌워지지 않게 해당 숫자 방문처리 하는 배열 사용했다. 👩‍💻 코드 import java.util.*; public class Main { static int n, m, k; static int[][] board,dis; static int[] ch,pm, combi, first, last; static boolean[] visited; static int[] dx = {-1,1,0,0}; static int[] dy = {0,0,-1,1}; public static void main(String[] args) { Main T = new Main(); Scanner kb = new Scann..

Algorithm/baekjoon 2022.01.19

스타트와 링크

📍 문제 설명 💡 접근 n명중에 2팀을 뽑아야하는데 여기서의 뽑히는 것의 구분은 boolean 값에 따라서 구별해준다. n명의 상태 정보 값이 모두 필요하다.(뽑히는 경우와 뽑히지 않는 경우) 👩‍💻 코드 import java.util.*; public class Main { static int n, m, k; static int[][] board,dis; static int[] ch,pm; static boolean[] combi; static int[] dx = {-1,1,0,0}; static int[] dy = {0,0,-1,1}; static int min = Integer.MAX_VALUE; public static void main(String[] args) { Main T = new Mai..

Algorithm/baekjoon 2022.01.18

스도쿠

📍 문제 설명 💡 접근 0,0에서부터 모든 열을 확인후 모든 행을 탐색하는 방식으로 풀면 됐다. 근데 해당 지점에 잘못된 숫자가 들어갔을 때의 처리가 문제였다. 문제에서 제일 중요한 부분이 3군데 있었다. 1.이전 row가 잘못 채워졌을 경우에 되돌아가기 위한 return; 2.스도쿠가 채워졌을 경우 바로 출력시키고 종료하는 System.exit(0); return;을 사용하면 안되는 이유는 마지막 탐색을 한다고 가정했을 때 스도쿠가 채워진다는 보장이 없기 때문임 3.들어갈 순 있지만 올바른 숫자가 아닐 때 다시 빈칸으로 만들고 + 되돌아가기 위한 return; return이 없다면, 해당 자리를 채웠는데 실패한 경우 다시 돌아오고나서 또 다시 다음 열을 탐색하게됨 위 사진의 스도쿠를 본다면 0,0 올바..

Algorithm/baekjoon 2022.01.18

알파벳

📍 문제 설명 💡 접근 알파벳 방문배열을 만들어서 방문한 알파벳을 만날 때 마다 현재 거리를 리턴해주면 된다. 그리고 방문체크 해제해줘야 다른 루트도 정상적으로 확인할 수 있다! 👩‍💻 코드 import java.util.*; public class Main { static int n, m, k, dis, max; static int[][] board; static int[] ch,combi,pm; static String[] split; static int[] dx = {-1,1,0,0}; static int[] dy = {0,0,-1,1}; //알파벳 방문여부 static boolean[] checked = new boolean[26]; public static void main(String[] ar..

Algorithm/baekjoon 2022.01.17

암호 만들기

📍 문제 설명 💡 접근 시간초과 판정이 나서 이것저것 해봤는데, 최종 문제는 순열로 풀었다는 것이다. 오름차순 정렬을 순열을 뽑고나서 진행하는게 아니라 정렬 먼저 한 다음 조합으로 뽑아내면된다. 👩‍💻 코드 import java.util.*; public class Main { static int n, m, k; static int[][] board,dis; static int[] ch; static String[] split,pm; static int[] dx = {-1,1,0,0}; static int[] dy = {0,0,-1,1}; static int[] combi; static ArrayList list = new ArrayList(); public static void main(String[]..

Algorithm/baekjoon 2022.01.17