본문 바로가기

Java70

[Java] 백준 [9095] 1, 2, 3 더하기 public class Solution { // 1, 2, 3 더하기 - DP 9095번 // n을 1, 2, 3의 합으로 나타내는 방법의 수 static int n = 4; static int[] dp = new int[101]; // 1+1+1+1 // 1+1+2 // 1+2+1 // 2+1+1 // 2+2 // 1+3 // 3+1 public static void main(String[] args) { // TODO Auto-generated method stub // n은 1일 때 1 // 2일 때 1+1, 2 // 3일 때 1+1+1, 1+2, 2+1, 3 // 4는 1+3/2+2/3+1로 나타낼 수 있음 // 1+(1+1+1)/2+(1+1)/3+(1) // 1+(1+2)/2+(2) // 1+(.. 2022. 12. 16.
[Java] 프로그래머스 [Level-3] 숫자 타자 대회 public class Solution { // 숫자 타자 대회 public static int[][] weight = { // 가중치 {1, 7, 6, 7, 5, 4, 5, 3, 2, 3}, // 0에서부터 0 ~ 9까지의 가중치 {7, 1, 2, 4, 2, 3, 5, 4, 5, 6}, // 1에서부터 0 ~ 9까지의 가중치 {6, 2, 1, 2, 3, 2, 3, 5, 4, 5}, // 2에서부터 0 ~ 9까지의 가중치 {7, 4, 2, 1, 5, 3, 2, 6, 5, 4}, // 3에서부터 0 ~ 9까지의 가중치 {5, 2, 3, 5, 1, 2, 4, 2, 3, 5}, // 4에서부터 0 ~ 9까지의 가중치 {4, 3, 2, 3, 2, 1, 2, 3, 2, 3}, // 5에서부터 0 ~ 9까지의 가중.. 2022. 12. 13.
[Java] 백준 [1697] 숨바꼭질 import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; public class Solution { // 숨바꼭질 - BFS 1697번 static int n = 5; static int m = 17; public static void bfs(int a, int b) { Queue q = new LinkedList(); int[] check = new int[100001]; // 0 ~ 17까지 만들자 boolean[] visit = new boolean[100001]; Arrays.fill(check, 0); // 전체 0으로 초기화 q.offer(n); //5 넣고 visit[n] = true; // 5 방문 while.. 2022. 12. 12.
[Java] 백준 [1303] 전쟁 - 전투 import java.util.ArrayList; public class Solution { // 전쟁 - 전투 - DFS 1303번 static int n = 5; static int m = 5; static char[][] arr = {{'W','B','W','W','W'}, {'W','W','W','W','W'}, {'B','B','B','B','B'}, {'B','B','B','W','W'}, {'W','W','W','W','W'}}; static boolean[][] visit = new boolean[5][5]; static int[] dy = {-1, 1, 0, 0}; static int[] dx = {0, 0, -1, 1}; static ArrayList wList = new ArrayLi.. 2022. 12. 10.
[Java] 백준 [11048] 이동하기 public class Solution { // 이동하기 - DP 11048번 static int n = 3; static int m = 4; static int[][] arr = {{1, 2, 3, 4}, {0, 0, 0, 5}, {9, 8, 7, 6}}; static int[] dy = {1, 1, 0}; static int[] dx = {0, 1, 1}; static int[][] dp = new int[n][m]; public static void dfs(int a, int b) { for (int i = 0; i n - 1 || nx > m - 1) { continue; } dp[ny][.. 2022. 12. 10.
[Java] 백준 [1026] 보물 import java.util.*; public class Solution { // 보물 - Greedy 1026번 public static int minVal(int n, int[] arrA, int[] arrB) { int[] arrTempA = arrA; Integer[] tempB = Arrays.stream(arrB).boxed().toArray(Integer[]::new); Arrays.sort(tempB, Collections.reverseOrder()); int[] arrTempB = Arrays.stream(tempB).mapToInt(Integer::intValue).toArray(); Arrays.sort(arrTempA); int numVal = 0; //for (int i = 0;.. 2022. 12. 10.
[Java] 프로그래머스 [Level-4] 쌍둥이 빌딩 숲 public class Solution { // 쌍둥이 빌딩 숲 // 전체 쌍둥이 빌딩의 수, 측면에서 봤을 때 보이는 빌딩의 수 [경우의 수] // 가장 높은 쌍둥이 빌딩부터 순서대로 배치 // 1, 1 = 11 [1개] // 2, 1 = 1221, 1122 [2개] 1 * 2 // 2, 2 = 2211 [1개] 1 // 3, 1 = 133221, 123321, 122331, 122133, 133122, 113322, 112332, 112233 [8개] 2 * 4 // 3, 2 = 233211, 223311, 221331, 221133, 331221, 331122 [6개] 1 * 4 + 2 // 3, 3 = 332211 [1개] 1 // 4, 1 = [48개] 8 * 6 // 4, 2 = [44개] 6.. 2022. 12. 6.
[Java] 프로그래머스 [Level-3] 순위 public class Solution { // 순위 // Floyd Warshall 알고리즘으로 풀이 public static int solution(int n, int[][] results) { int answer = 0; int zeroCnt = 0; int[][] board = new int[n][n]; // 0 ~ 4 for (int i = 0; i < results.length; i++) { // {4, 3}의 경우 board[results[i][0] - 1][results[i][1] - 1] = 1; // 4는 3에게 이겼으므로 board[3][2] = 1 board[results[i][1] - 1][results[i][0] - 1] = -1; // 3은 4에게 졌으므로 board[2][3].. 2022. 11. 29.
[Java] 프로그래머스 [Level-2] 롤케이크 자르기 import java.util.HashMap; public class Solution { // 롤케이크 자르기 public static int solution(int[] topping) { int answer = 0; HashMap hm1 = new HashMap(); HashMap hm2 = new HashMap(); for (int i = 0; i < topping.length; i++) { hm2.put(topping[i], hm2.getOrDefault(topping[i], 0) + 1); } // hm2 : {1=4, 2=2, 3=1, 4=1} for (int i = 0; i < topping.length; i++) { hm1.put(topping[i], hm1.getOrDefault(toppi.. 2022. 11. 29.