-
Notifications
You must be signed in to change notification settings - Fork 0
[Week05] 덱 / 양민섭 #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BokSIL-SEOB
wants to merge
1
commit into
main
Choose a base branch
from
minseob
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Week05] 덱 / 양민섭 #25
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
algorithm-study/src/main/java/week05/boj13417/카드문자열_양민섭.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package main.java.week05.boj13417; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.Deque; | ||
| import java.util.LinkedList; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| public class 카드문자열_양민섭 { | ||
| //메모리 : 29296KB, 시간 : 284ms | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| int T = Integer.parseInt(br.readLine()); // 테스트 데이터 개수 | ||
|
|
||
| StringBuilder result = new StringBuilder(); | ||
|
|
||
| for (int t = 0; t < T; t++) { | ||
| int N = Integer.parseInt(br.readLine()); // 카드 개수 | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
|
||
| Deque<Character> deque = new LinkedList<>(); | ||
|
|
||
| // 첫번째 카드 | ||
| deque.add(st.nextToken().charAt(0)); | ||
| // 나머지 카드 | ||
| for (int i = 1; i < N; i++) { | ||
| char c = st.nextToken().charAt(0); | ||
| if (c <= deque.peekFirst()) { // char 은 기본형 타입이라 null 못 받음. 그래서 NPE 경고 나옴. | ||
| deque.addFirst(c); // 가장 앞 글자보다 작 . 같 왼쪽에 추가 | ||
| } else { | ||
| deque.addLast(c); // 아니라면 오른쪽에 추가 | ||
| } | ||
| } | ||
|
|
||
| // 덱을 문자열로 변환 | ||
| StringBuilder sb = new StringBuilder(); | ||
| for (char c : deque) { | ||
| sb.append(c); | ||
| } | ||
| result.append(sb).append("\n"); // 테스트끼리 분리 | ||
| } | ||
| System.out.print(result); | ||
| } | ||
| } | ||
58 changes: 58 additions & 0 deletions
58
algorithm-study/src/main/java/week05/boj20301/반전_요세푸스_양민섭.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package main.java.week05.boj20301; | ||
|
|
||
| import java.io.*; | ||
| import java.util.LinkedList; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| public class 반전_요세푸스_양민섭 { | ||
| public static void main(String[] args) throws Exception { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
|
||
| int N = Integer.parseInt(st.nextToken()); | ||
| int K = Integer.parseInt(st.nextToken()); | ||
| int M = Integer.parseInt(st.nextToken()); | ||
|
|
||
| // 사람들을 1..N까지 넣어둔다 | ||
| LinkedList<Integer> circle = new LinkedList<>(); | ||
| for (int i = 1; i <= N; i++) { | ||
| circle.add(i); | ||
| } | ||
|
|
||
| StringBuilder out = new StringBuilder(); | ||
|
|
||
| boolean clockwise = true; // 처음엔 오른쪽(시계 방향)으로 돈다 | ||
| int removed = 0; // 지금까지 제거된 사람 수 | ||
|
|
||
| while (!circle.isEmpty()) { | ||
| if (clockwise) { | ||
| // 시계 방향: K-1번 앞에서 빼서 뒤에 붙인다 | ||
| for (int i = 0; i < K - 1; i++) { | ||
| int x = circle.removeFirst(); | ||
| circle.addLast(x); | ||
| } | ||
| // K번째를 제거 | ||
| int dead = circle.removeFirst(); | ||
| out.append(dead).append('\n'); | ||
| } else { | ||
| // 반시계 방향: K-1번 뒤에서 빼서 앞에 붙인다 | ||
| for (int i = 0; i < K - 1; i++) { | ||
| int x = circle.removeLast(); | ||
| circle.addFirst(x); | ||
| } | ||
| // K번째를 제거 (반시계라서 뒤에서 제거) | ||
| int dead = circle.removeLast(); | ||
| out.append(dead).append('\n'); | ||
| } | ||
|
|
||
| removed++; | ||
|
|
||
| // M명 제거될 때마다 방향을 뒤집는다 | ||
| if (removed % M == 0) { | ||
| clockwise = !clockwise; | ||
| } | ||
| } | ||
|
|
||
| System.out.print(out.toString()); | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
algorithm-study/src/main/java/week05/boj2346/풍선_터뜨리기_양민섭.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package main.java.week05.boj2346; | ||
|
|
||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| public class 풍선_터뜨리기_양민섭 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| int N = Integer.parseInt(br.readLine()); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
|
||
| Deque<int[]> dq = new ArrayDeque<>(); | ||
| // [번호, 이동값] | ||
| for (int i = 1; i <= N; i++) { | ||
| int move = Integer.parseInt(st.nextToken()); | ||
| dq.addLast(new int[]{i, move}); | ||
| } | ||
|
|
||
| StringBuilder sb = new StringBuilder(); | ||
|
|
||
| int[] current = dq.pollFirst(); // 첫 풍선 터뜨리기 | ||
| sb.append(current[0]).append(' '); | ||
|
|
||
| while (!dq.isEmpty()) { | ||
| int move = current[1]; | ||
|
|
||
| if (move > 0) { | ||
| // 오른쪽(앞)으로 move-1번 회전 | ||
| for (int i = 0; i < move - 1; i++) { | ||
| dq.addLast(dq.pollFirst()); | ||
| } | ||
| current = dq.pollFirst(); | ||
| } else { | ||
| // 왼쪽(뒤)으로 |move|-1번 회전 | ||
| for (int i = 0; i < (-move) - 1; i++) { | ||
| dq.addFirst(dq.pollLast()); | ||
| } | ||
| current = dq.pollLast(); | ||
| } | ||
|
|
||
| sb.append(current[0]).append(' '); | ||
| } | ||
|
|
||
| System.out.println(sb.toString().trim()); | ||
| } | ||
| } |
105 changes: 105 additions & 0 deletions
105
out/production/algorithm-study/main/java/week01/boj15649/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| # BOJ 15649 | ||
|
|
||
| 문제) 자연수 N과 M이 주어졌을 때, 아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오. | ||
|
|
||
| - 조건) 1부터 N까지 자연수 중에서 중복 없이 M개를 고른 수열 | ||
| - 예) N=4, M=2 : [1,2], [1,3], [1,4], [2,1], [2,3], [2,4], [3,1], [3,2], [3,4], [4,1], [4,2], [4,3] | ||
|
|
||
| ## 백트래킹 | ||
| - 시도 -> 실패 -> 되돌아감을 반복하면서 정답을 찾아가는 알고리즘 | ||
| - 재귀적으로 문제를 해결한다. | ||
| - 재귀 -> 본인을 다시 호출 (예: 팩토리얼) | ||
| ```java | ||
| public class Factorial { | ||
| public static void main(String[] args) { | ||
| System.out.println(factorial(4)); | ||
| } | ||
|
|
||
| public static int factorial(int n) { | ||
| if (n == 1) return 1; | ||
|
|
||
| return n * factorial(n - 1); | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| n = 4 -> 4 * factorial(3) ==> 24 | ||
| n = 3 -> 3 * factorial(2) ==> 6 | ||
| n = 2 -> 2 * factorial(1) ==> 2 | ||
| n = 1 -> 1 | ||
| */ | ||
|
|
||
| ``` | ||
|
|
||
| ## 수열 | ||
| - 예제) 1부터 4까지 자연수 중에서 중복 없이 3개를 고른 수열 | ||
| ``` | ||
| depth (0) (1) (2) | ||
| 1 ────── 2 ────── 3 | ||
| │ └── 4 | ||
| │ | ||
| ├─── 3 ────── 2 | ||
| │ └── 4 | ||
| │ | ||
| └─── 4 ────── 2 | ||
| └── 3 | ||
|
|
||
| 2 ... | ||
| ``` | ||
|
|
||
| - `boolean visited[n]` : 방문한 숫자를 알아낸다. | ||
| - `int[] arr[m]` : 수열을 배열 형태로 저장 | ||
| - `int depth` : 몇 번째 수열인지 가르키기 위한 값 | ||
|
|
||
| ``` | ||
| static void backtracking(int depth) { | ||
| if (depth == arr.length) { | ||
| for (int value : arr) { | ||
| System.out.print(value + " "); | ||
| } | ||
| System.out.println(); | ||
| return; | ||
| } | ||
|
|
||
| for (int i = 0; i < visited.length; i++) { | ||
| if (!visited[i]) { | ||
| visited[i] = true; | ||
| arr[depth] = i + 1; | ||
| backtracking(depth + 1); | ||
| visited[i] = false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # backtracking(0) -> i = 0, visitied[0] = true, arr[0] = 1, backtracking(1) | ||
| └── ## backtracking(1) -> i = 0, visited[0] 이미 true | ||
| -> i = 1, visited[1] = true, arr[1] = 2, backtracking(2) | ||
| └── ### backtracking(2) -> i = 0, visited[0] 이미 true | ||
| -> i = 1, visited[1] 이미 true | ||
| -> i = 2, visited[2] = true, arr[2] = 3, backtracking(3) | ||
| └── #### backtracking(3) -> depth == arr.length, [1, 2, 3] ==> visited[2] = false | ||
|
|
||
| -> i = 3, visited[3] = true, arr[3] = 4, backtracking(3) | ||
| └── #### backtracking(3) -> depth == arr.length, [1, 2, 4] ==> visited[3] = false | ||
|
|
||
| -> i = 2, visited[2] = true, arr[2] = 3, backtrakcing(2) | ||
| └── ### backtracking(2) -> i = 0, visited[0] 이미 true | ||
| -> i = 1, visited[1] = true, arr[2] = 2, backtracking(3) | ||
| └── #### backtracking(3) -> depth == arr.length, [1, 3, 2] ==> visited[1] = false | ||
|
|
||
| -> i = 2, visited[2] 이미 true | ||
| -> i = 3, visited[3] = true, arr[2] = 4, backtracking(3) | ||
| └── #### backtracking(3) -> depth == arr.length, [1, 3, 4] ==> visited[3] = false | ||
|
|
||
| -> i = 3, visited[3] = true, arr[3] = 4, backtracking(2) | ||
| └── ### backtracking(2) -> i = 0, visited[0] 이미 true | ||
| -> i = 1, visited[1] = true, arr[2] = 2, backtracking(3) | ||
| └── #### backtracking(3) -> depth == arr.length, [1, 4, 2] ==> visited[1] = false | ||
|
|
||
| -> i = 2, visited[2] = true, arr[2] = 3, backtracking(3) | ||
| └── #### backtracking(3) -> depth == arr.length, [1, 4, 3] ==> visited[2] = false | ||
|
|
||
| -> i = 3, visited[3] 이미 true | ||
|
|
||
| -> i = 1, ... | ||
| ``` |
61 changes: 61 additions & 0 deletions
61
out/production/algorithm-study/main/java/week02/boj17219/problem.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # [비밀번호 찾기](https://www.acmicpc.net/problem/17219) | ||
|
|
||
| ## 문제 | ||
| - 2019 HEPC - MAVEN League의 "비밀번호 만들기"와 같은 방식으로 비밀번호를 만든 경민이는 한 가지 문제점을 발견하였다. | ||
| - 비밀번호가 랜덤으로 만들어져서 기억을 못 한다는 것이었다! 그래서 경민이는 메모장에 사이트의 주소와 비밀번호를 저장해두기로 했다. | ||
| - 하지만 컴맹인 경민이는 메모장에서 찾기 기능을 활용하지 못하고 직접 눈으로 사이트의 주소와 비밀번호를 찾았다. | ||
| - 메모장에 저장된 사이트의 수가 늘어나면서 경민이는 비밀번호를 찾는 일에 시간을 너무 많이 쓰게 되었다. | ||
| - 이를 딱하게 여긴 문석이는 경민이를 위해 메모장에서 비밀번호를 찾는 프로그램을 만들기로 결심하였다! | ||
| - 문석이를 도와 경민이의 메모장에서 비밀번호를 찾아주는 프로그램을 만들어보자. | ||
|
|
||
| --- | ||
|
|
||
| ## 입력 | ||
| - 첫째 줄에 저장된 사이트 주소의 수 N(1 ≤ N ≤ 100,000)과 비밀번호를 찾으려는 사이트 주소의 수 M(1 ≤ M ≤ 100,000)이 주어진다. | ||
| - 두번째 줄부터 N개의 줄에 걸쳐 각 줄에 사이트 주소와 비밀번호가 공백으로 구분되어 주어진다. | ||
| - 사이트 주소는 알파벳 소문자, 알파벳 대문자, 대시('-'), 마침표('.')로 이루어져 있고, | ||
| - 중복되지 않는다. | ||
| - 비밀번호는 알파벳 대문자로만 이루어져 있다. | ||
| - 모두 길이는 최대 20자이다. | ||
| - N+2번째 줄부터 M개의 줄에 걸쳐 비밀번호를 찾으려는 사이트 주소가 한줄에 하나씩 입력된다. | ||
| - 이때, 반드시 이미 저장된 사이트 주소가 입력된다. | ||
|
|
||
| --- | ||
|
|
||
| ## 출력 | ||
| 첫 번째 줄부터 M개의 줄에 걸쳐 비밀번호를 찾으려는 사이트 주소의 비밀번호를 차례대로 각 줄에 하나씩 출력한다. | ||
|
|
||
| --- | ||
|
|
||
| ## 예제 입력 | ||
| ```markdown | ||
| 16 4 | ||
| noj.am IU | ||
| acmicpc.net UAENA | ||
| startlink.io THEKINGOD | ||
| google.com ZEZE | ||
| nate.com VOICEMAIL | ||
| naver.com REDQUEEN | ||
| daum.net MODERNTIMES | ||
| utube.com BLACKOUT | ||
| zum.com LASTFANTASY | ||
| dreamwiz.com RAINDROP | ||
| hanyang.ac.kr SOMEDAY | ||
| dhlottery.co.kr BOO | ||
| duksoo.hs.kr HAVANA | ||
| hanyang-u.ms.kr OBLIVIATE | ||
| yd.es.kr LOVEATTACK | ||
| mcc.hanyang.ac.kr ADREAMER | ||
| startlink.io | ||
| acmicpc.net | ||
| noj.am | ||
| mcc.hanyang.ac.kr | ||
| ``` | ||
|
|
||
| ## 예제 출력 | ||
| ```markdown | ||
| THEKINGOD | ||
| UAENA | ||
| IU | ||
| ADREAMER | ||
| ``` |
39 changes: 39 additions & 0 deletions
39
out/production/algorithm-study/main/java/week02/boj1764/problem.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # [듣보잡](https://www.acmicpc.net/problem/1764) | ||
|
|
||
| ## 문제 | ||
| - 김진영이 듣도 못한 사람의 명단과, 보도 못한 사람의 명단이 주어질 때, | ||
| - 듣도 보도 못한 사람의 명단을 구하는 프로그램을 작성하시오. | ||
|
|
||
| --- | ||
|
|
||
| ## 입력 | ||
| - 첫째 줄에 듣도 못한 사람의 수 N, 보도 못한 사람의 수 M이 주어진다. | ||
| - 이어서 둘째 줄부터 N개의 줄에 걸쳐 듣도 못한 사람의 이름과, N+2째 줄부터 보도 못한 사람의 이름이 순서대로 주어진다. | ||
| - 이름은 띄어쓰기 없이 알파벳 **소문자로만** 이루어지며, 그 길이는 20 이하이다. N, M은 **500,000 이하의 자연수**이다. | ||
| - 듣도 못한 사람의 명단에는 **중복되는 이름이 없으며**, 보도 못한 사람의 명단도 마찬가지이다. | ||
|
|
||
| --- | ||
|
|
||
| ## 출력 | ||
| - 듣보잡의 수와 그 명단을 **사전순으로 출력**한다. | ||
|
|
||
| --- | ||
|
|
||
| ## 예제 입력 | ||
| ```markdown | ||
| 3 4 | ||
| ohhenrie | ||
| charlie | ||
| baesangwook | ||
| obama | ||
| baesangwook | ||
| ohhenrie | ||
| clinton | ||
| ``` | ||
|
|
||
| ## 예제 출력 | ||
| ```markdown | ||
| 2 | ||
| baesangwook | ||
| ohhenrie | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
보통 LinkedList 보다 ArrayDeque 가 성능이 더 좋다고 알고 있는데, 변경하셔도 메모리와 시간이 큰 차이가 없는지 궁금하네요!