diff --git "a/jinhyun/BOJ/Main_BJ_1049_\352\270\260\355\203\200\354\244\204.java" "b/jinhyun/BOJ/Main_BJ_1049_\352\270\260\355\203\200\354\244\204.java" new file mode 100644 index 0000000..e401a27 --- /dev/null +++ "b/jinhyun/BOJ/Main_BJ_1049_\352\270\260\355\203\200\354\244\204.java" @@ -0,0 +1,81 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.StringTokenizer; + +public class Main_BJ_1049_기타줄 { + + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int ans = 1000; + + st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); // 끊어진 줄 수 + int M = Integer.parseInt(st.nextToken()); // 브랜드 수 + + List list = new ArrayList<>(); + + for(int i = 0; i() { + @Override + public int compare(int[] o1, int[] o2) { + if(o1[0] < o2[0]){ + return -1; + }else if (o1[0]> o2[0]){ + return 1; + } + return 0; + } + }); + + + // 6개 패키지로만 수량 채우는 방법 + if(N <= 6 ) { + ans = list.get(0)[0]; + }else { + ans = N%6==0 ? list.get(0)[0] * (N / 6) : list.get(0)[0] * (N / 6 + 1); + } + + int temp = 0; + // 6개 패키지로 일정부분 채우고 낱개로 일정부분 채우는 방법 + temp = list.get(0)[0] * (N/6); + // 낱개 기준으로 정렬 + Collections.sort(list, new Comparator() { + @Override + public int compare(int[] o1, int[] o2) { + if(o1[1] < o2[1]){ + return -1; + }else if (o1[1]> o2[1]){ + return 1; + } + return 0; + } + }); + temp += (N%6) * list.get(0)[1]; + if (ans > temp) { + ans = temp; + } + + // 낱개로만 수량 채우는 방법 + temp = N * list.get(0)[1]; + if(ans > temp) { + ans = temp; + } + + + System.out.print(ans); + } + +} diff --git "a/jinhyun/BOJ/Main_BJ_10971_\354\231\270\355\214\220\354\233\220_\354\210\234\355\232\2142.java" "b/jinhyun/BOJ/Main_BJ_10971_\354\231\270\355\214\220\354\233\220_\354\210\234\355\232\2142.java" new file mode 100644 index 0000000..c47665b --- /dev/null +++ "b/jinhyun/BOJ/Main_BJ_10971_\354\231\270\355\214\220\354\233\220_\354\210\234\355\232\2142.java" @@ -0,0 +1,75 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_BJ_10971_외판원_순회2 { + + static boolean[] isVisited; + static int[] pick; + static int[][] W; + static int N; + static int ans; + public static void main(String[] args) throws Exception{ + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); // 도시 수 + isVisited = new boolean[N]; // 방문 체크 + pick = new int[N]; // 선택한 수열(순열) + W = new int[N][N]; // cost 입력 + ans = Integer.MAX_VALUE; // 최저값 구하기 위해서 최대값으로 초기화 + + for(int i = 0; i cost) { + ans = cost; + } + + }// calc + +} + + diff --git "a/jinhyun/BOJ/Main_BJ_1342_\355\226\211\354\232\264\354\235\230_\353\254\270\354\236\220\354\227\264.java" "b/jinhyun/BOJ/Main_BJ_1342_\355\226\211\354\232\264\354\235\230_\353\254\270\354\236\220\354\227\264.java" new file mode 100644 index 0000000..f728035 --- /dev/null +++ "b/jinhyun/BOJ/Main_BJ_1342_\355\226\211\354\232\264\354\235\230_\353\254\270\354\236\220\354\227\264.java" @@ -0,0 +1,72 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +public class Main_BJ_1342_행운의_문자열 { + + static boolean[] isVisited; + static char[] ans; + static int[] arr; + static int totalCnt; + + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String s = br.readLine(); + arr = new int[26]; + isVisited = new boolean[s.length()]; + ans = new char[s.length()]; + totalCnt = 0; + perm(0, 0, s); + + for (int i = 0; i < s.length(); i++) { + arr[s.charAt(i) - 'a']++; + } + + //팩토리얼로 나눠주어 생성된 문자열의 중복을 정확히 없앨 수 있음 (aabbbaa)의 경우 144개 -> 1개 + //set으로 풀이하면 메모리 초과 발생 + for (int i = 0; i < 26; i++) { + if (arr[i] > 1) + totalCnt /= factorial(arr[i]); + } + + System.out.println(totalCnt); + } + + static void perm(int cnt, int flag, String s) { + if(cnt == s.length()) { + if(isVerified()) { + totalCnt++; + } + return; + } + + for(int i = 0; i redQ = new ArrayDeque<>(); + Queue blueQ = new ArrayDeque<>(); + + // 처음 위치 방문 처리 + visited[r_ball.x][r_ball.y][b_ball.x][b_ball.y] = true; + + redQ.offer(r_ball); + blueQ.offer(b_ball); + + while (!redQ.isEmpty() && !blueQ.isEmpty()) { + Ball nr_ball = redQ.poll(); + Ball nb_ball = blueQ.poll(); + + // 10회 초과시 종료 + if (nr_ball.count > 10) { + ans = -1; + return; + } + + // 파란공이 구멍에 도착한 경우 : 실패 + if (map[nb_ball.x][nb_ball.y] == 'O') { + continue; + } + + // 빨간공만 구멍에 도착한 경우 : 성공 + if (map[nr_ball.x][nr_ball.y] == 'O') { + ans = nr_ball.count; + return; + } + + // 상하좌우로 기울이기 + for (int d = 0; d < 4; d++) { + + // 파란공이 이동가능한 지점까지 이동 + int bx = nb_ball.x; + int by = nb_ball.y; + while (true) { + bx += dx[d]; + by += dy[d]; + if (map[bx][by] == 'O') // 구멍 도착 + break; + else if (map[bx][by] == '#') { // 벽에 도착 (도착하기 이전 칸으로 수정) + bx -= dx[d]; + by -= dy[d]; + break; + } + } + + // 빨간공이 이동가능한 지점까지 이동 + int rx = nr_ball.x; + int ry = nr_ball.y; + while (true) { + rx += dx[d]; + ry += dy[d]; + // 빠져나간 경우 + if (map[rx][ry] == 'O') + break; + // 벽을 만난 경우 + else if (map[rx][ry] == '#') { + rx -= dx[d]; + ry -= dy[d]; + break; + } + } + + if (bx == rx && by == ry && map[rx][ry] != 'O') { // 도착 지점이 동일하지만 구멍이 아닌 경우(앞서 출발한 공이 앞에 위치해야한다.) + if(d == 0) {//상 + if(nr_ball.x < nb_ball.x) { + bx -=dx[d]; + by -=dy[d]; + }else { + rx -=dx[d]; + ry -=dy[d]; + } + } + if(d == 1) {//하 + if(nr_ball.x > nb_ball.x) { + bx -=dx[d]; + by -=dy[d]; + }else { + rx -=dx[d]; + ry -=dy[d]; + } + } + if(d == 2) {//좌 + if(nr_ball.y < nb_ball.y) { + bx -=dx[d]; + by -=dy[d]; + }else { + rx -=dx[d]; + ry -=dy[d]; + } + } + if(d == 3) {//우 + if(nr_ball.y > nb_ball.y) { + bx -=dx[d]; + by -=dy[d]; + }else { + rx -=dx[d]; + ry -=dy[d]; + } + } + } + + // 다음 좌표 방문 처리 및 큐에 추가 + if (!visited[rx][ry][bx][by]) { + // 방문처리 + visited[rx][ry][bx][by] = true; + + // 큐에 추가 + redQ.offer(new Ball(rx, ry, nr_ball.count + 1)); + blueQ.offer(new Ball(bx, by, nb_ball.count + 1)); + } + } + + } + } + +} \ No newline at end of file diff --git "a/jinhyun/BOJ/Main_BJ_1654_\353\236\234\354\204\240_\354\236\220\353\245\264\352\270\260.java" "b/jinhyun/BOJ/Main_BJ_1654_\353\236\234\354\204\240_\354\236\220\353\245\264\352\270\260.java" new file mode 100644 index 0000000..28939b0 --- /dev/null +++ "b/jinhyun/BOJ/Main_BJ_1654_\353\236\234\354\204\240_\354\236\220\353\245\264\352\270\260.java" @@ -0,0 +1,50 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_BJ_1654_랜선_자르기 { + + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + st = new StringTokenizer(br.readLine()); + int K = Integer.parseInt(st.nextToken()); // 영식이가 갖고 있는 랜선 K개 + int N = Integer.parseInt(st.nextToken()); // 영식이가 필요한 랜선 N개 + + int[] k_lans = new int[K]; + int max = 0; + + // K개의 랜선 각 길이 입력 + for(int i =0; i= N) { + ans = Math.max(ans, mid); + low = mid+1; + } + if (count < N) { + high = mid-1; + } + } + + System.out.println(ans); + + }//main + +} diff --git "a/jinhyun/BOJ/Main_BJ_18111_\353\247\210\354\235\270\355\201\254\353\236\230\355\224\204\355\212\270.java" "b/jinhyun/BOJ/Main_BJ_18111_\353\247\210\354\235\270\355\201\254\353\236\230\355\224\204\355\212\270.java" new file mode 100644 index 0000000..fee6c8b --- /dev/null +++ "b/jinhyun/BOJ/Main_BJ_18111_\353\247\210\354\235\270\355\201\254\353\236\230\355\224\204\355\212\270.java" @@ -0,0 +1,94 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_BJ_18111_마인크래프트 { + + + // 블록 제거 : 2초 + // 블록 쌓기 : 1초 + static int N, M, B; + static int[][] map; + 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()); // 1<=M,N<=500 + M = Integer.parseInt(st.nextToken()); + B = Integer.parseInt(st.nextToken()); // 주어진 블록수 + + map = new int[N][M]; + int[][] new_map = new int[N][M]; + + // 복사 + for(int i = 0; i value) { + minH = value; + } + } + } + + int build_block; + int remove_block; + int now; + + // 최소 높이부터 최대 높이 블록까지 반복 + for(int h = minH; h<= maxH; h++) { + build_block = 0; + remove_block = 0; + + // 해당 높이에서 회수할 블록, 설치할 블록 구하기 + for(int i = 0; i< N; i++) { + for(int j = 0; j now) { // 현재 블록이 h보다 낮으면 설치할 블록 개수 누적 + build_block += (h - now); + } + if(h < now) { // 현재 블록이 h보다 높으면 회수할 블록 개수 누적 + remove_block += (now - h); + } + } + } + + // 설치할 블록 개수가 인벤토리와 회수한 블록의합보다 부족한지 검사 + if (build_block <= remove_block + B) { + time = remove_block * 2 + build_block; + + if (timeMin >= time) { + if (targetHeight > h) continue; + timeMin = time; + targetHeight = h; + } + } + + + } + + + System.out.println(timeMin +" "+targetHeight); + + + }//main + + +} diff --git "a/jinhyun/BOJ/Main_BJ_18870_\354\242\214\355\221\234_\354\225\225\354\266\225.java" "b/jinhyun/BOJ/Main_BJ_18870_\354\242\214\355\221\234_\354\225\225\354\266\225.java" new file mode 100644 index 0000000..fc77d0a --- /dev/null +++ "b/jinhyun/BOJ/Main_BJ_18870_\354\242\214\355\221\234_\354\225\225\354\266\225.java" @@ -0,0 +1,44 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; +import java.util.StringTokenizer; + +public class Main_BJ_18870_좌표_압축 { + + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + int N = Integer.parseInt(br.readLine()); + st = new StringTokenizer(br.readLine()); + + // 원본 배열 + Integer[] original = new Integer[N]; + + for(int i = 0; i set = new HashSet<>(Arrays.asList(original)); + // set -> array + Integer[] tempList = set.toArray(new Integer[0]); + // 배열 정렬 + Arrays.sort(tempList); + + HashMap map = new HashMap<>(); + for(int i = 0 ; i> 1; + if (nums[mid] == n) { + return true; + } + if (nums[mid] < n) { + lo = mid + 1; + } + else { + hi = mid - 1; + } + } + return false; + + } +} \ No newline at end of file diff --git "a/jinhyun/BOJ/Main_BJ_2078_\353\254\264\355\225\234\354\235\264\354\247\204\355\212\270\353\246\254.java" "b/jinhyun/BOJ/Main_BJ_2078_\353\254\264\355\225\234\354\235\264\354\247\204\355\212\270\353\246\254.java" new file mode 100644 index 0000000..f0b1f5b --- /dev/null +++ "b/jinhyun/BOJ/Main_BJ_2078_\353\254\264\355\225\234\354\235\264\354\247\204\355\212\270\353\246\254.java" @@ -0,0 +1,40 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_BJ_2078_무한이진트리 { + + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + StringBuilder sb = new StringBuilder(); + + st = new StringTokenizer(br.readLine()); + + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + + int L = 0; // 왼쪽으로 이동한 회수 + int R = 0; // 오른쪽으로 이동한 회수 + + while(a != b) { // a와 b가 같아질 때까지 반복 : 루트노드 + //루트 노드 이외에 절대 a와 b는 같을 수 없다. + // 부모 노드 값 재현 + if(a > b) { + L += 1; + a -= b; + } + if(a < b) { + R += 1; + b -= a; + } + } + + sb.append(L).append(" ").append(R); + + System.out.println(sb); + + }//main + +} + \ No newline at end of file diff --git "a/jinhyun/BOJ/Main_BJ_2078_\353\254\264\355\225\234\354\235\264\354\247\204\355\212\270\353\246\2542.java" "b/jinhyun/BOJ/Main_BJ_2078_\353\254\264\355\225\234\354\235\264\354\247\204\355\212\270\353\246\2542.java" new file mode 100644 index 0000000..8a81630 --- /dev/null +++ "b/jinhyun/BOJ/Main_BJ_2078_\353\254\264\355\225\234\354\235\264\354\247\204\355\212\270\353\246\2542.java" @@ -0,0 +1,47 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main_BJ_2078_무한이진트리2 { + + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + StringBuilder sb = new StringBuilder(); + + st = new StringTokenizer(br.readLine()); + + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + + int L = 0; // 왼쪽으로 이동한 회수 + int R = 0; // 오른쪽으로 이동한 회수 + + while(true) { + // 다음 연산을 통해서 연속적으로 L 또는 R로 이동하는 경우를 체크할 수 있다. + if(a > b) { + L += a/b; // b의 크기에 따라서 L의 값이 결정된다. b의 크기가 유지된 회수 = 좌측 이동 회수 + a = a%b; // L방향으로 이동하고도 남은 a의 값을 저장한다. + if (a == 0) { // 종료 조건 (b가 1이 되고 a%b == 0이 되는 상황을 고려) + L -= 1; // 1로 나눠진 경우 원하는 결과보다 1 큰 값이 L에 추가되기 떄문에 -1해준다. + break; + } + } + else if(a < b) { + R += b/a; + b = b%a; + if (b == 0) { + R -= 1; + break; + } + } + } + + sb.append(L).append(" ").append(R); + + System.out.println(sb); + + }//main + +} + \ No newline at end of file diff --git "a/jinhyun/BOJ/Main_BJ_3663_\352\263\240\353\223\235\354\240\220.java" "b/jinhyun/BOJ/Main_BJ_3663_\352\263\240\353\223\235\354\240\220.java" new file mode 100644 index 0000000..46eff0b --- /dev/null +++ "b/jinhyun/BOJ/Main_BJ_3663_\352\263\240\353\223\235\354\240\220.java" @@ -0,0 +1,59 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +public class Main_BJ_3663_고득점 { + + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int T = Integer.parseInt(br.readLine()); // 테스트케이스 수 + + + for(int tc = 0; tc= 'A' && c <= 'N') { + count += c-'A'; + } + else { + count += 'Z' - c + 1; + } + } + return count; + } + + // 좌우 이동 횟수 + static int calcLeftRight(String name) { + int size = name.length(); + int count = size - 1; // 좌우 이동의 최대값을 count값으로 설정 + + for (int i = 0; i < size; i++) + { + int next = i + 1; + while (next < size && 'A' == name.charAt(next)) { + next++; + } + count = Math.min(count, i + size - next + Math.min(i, size - next)); + } + + return count; + } +}