-
Notifications
You must be signed in to change notification settings - Fork 5
Minjeong / 5월 2주차 / 8문제 #208
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4db6900
[BOJ] #2512. 예산 / 실버2 / 40분 / 실패
Mingguriguri d63e8e9
[PGS] 전화번호목록 / Level2 (Java 풀이) / 30분 / 실패
Mingguriguri 60a1efb
[PGS] 올바른 괄호 / 실버2 / 40분 / 자바 풀이 / 힌트, 성공
Mingguriguri 8612d03
[PGS] 올바른 괄호 / 실버2 / 40분 / 자바 풀이 / 힌트, 성공
Mingguriguri f164643
[PGS] 기능개발 / Level2 (Java 풀이) / 30분 / 힌트, 성공
Mingguriguri be745b2
[PGS] 프로세스 / Level2 (Java 풀이) / 52분 / 실패
Mingguriguri 8b08e1e
[BOJ] #1283. 단축키 지정 / 실버1 / 40분 / 힌트, 성공
Mingguriguri 2ac22bc
[BOJ] #2564. 경비원 / 실버1 / 60분 / 실패
Mingguriguri 18f9e8c
[PGS] 같은 숫자는 싫어 / Level 1 / 15분 / 성공
Mingguriguri 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
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,37 @@ | ||
| import sys | ||
|
|
||
| input = sys.stdin.readline | ||
|
|
||
| def main(): | ||
| N = int(input()) # 지방의 수 | ||
| budgets = sorted(map(int, input().split())) # 각 지방의 예상요청 | ||
| M = int(input()) # 총 예산 | ||
|
|
||
| # 1. 모든 요청이 배정될 수 있는 경우, 요청 최대값이 정답 | ||
| if sum(budgets) <= M: | ||
| return budgets[-1] | ||
|
|
||
| # 2. 모든 요청이 배정될 수 없는 경우, 상한액 탐색 | ||
| left = 0 | ||
| right = budgets[-1] | ||
| answer = 0 | ||
|
|
||
| while left <= right: | ||
| mid = (left + right) // 2 # 상한액 | ||
| total = 0 | ||
| for b in budgets: | ||
| total += min(b, mid) | ||
|
|
||
| if total <= M: | ||
| # 이 상한액으로 배정해도 총액이 허용 범위 이내 → C를 더 높여 볼 수 있음 | ||
| answer = mid | ||
| left = mid + 1 | ||
| else: | ||
| # 총액이 초과 → 상한액을 낮춰야 함 | ||
| right = mid - 1 | ||
|
|
||
| return answer | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| print(main()) |
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,32 @@ | ||
| import sys | ||
|
|
||
| input = sys.stdin.readline | ||
|
|
||
|
|
||
| def setOptions(option): | ||
| # 1. 각 단어의 첫 글자 우선 확인 | ||
| for i in range(len(option)): | ||
| if option[i][0].upper() not in shortcut_key: | ||
| shortcut_key.add(option[i][0].upper()) | ||
| option[i] = f"[{option[i][0]}]{option[i][1:]}" | ||
| return option | ||
|
|
||
| # 2. 전체 단어의 모든 글자 중 아직 등록되지 않은 글자 탐색 | ||
| for i in range(len(option)): | ||
| for j in range(len(option[i])): | ||
| if option[i][j].upper() not in shortcut_key: | ||
| shortcut_key.add(option[i][j].upper()) | ||
| option[i] = f"{option[i][:j]}[{option[i][j]}]{option[i][j + 1:]}" | ||
| return option | ||
|
|
||
| # 3. 지정할 수 있는 단축키가 없는 경우 | ||
| return option | ||
|
|
||
|
|
||
| N = int(input()) | ||
| shortcut_key = set() | ||
|
|
||
| for _ in range(N): | ||
| option = input().split() | ||
| result = setOptions(option) | ||
| print(' '.join(result)) | ||
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,44 @@ | ||
| import sys | ||
| input = sys.stdin.readline | ||
|
|
||
| # 1. 입력받기 | ||
| w, h = map(int, input().split()) # 가로, 세로 | ||
| store_cnt = int(input()) # 상점의 개수 | ||
|
|
||
| # 2. 둘레 계산 | ||
| perimeter = 2 * (w + h) | ||
|
|
||
| # 3. (방향, 거리) -> 1차원 위치로 변환 함수 | ||
| def to_pos(dir, dist): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 문제에서는 직사각형 블록 외각에만 길이 있기 때문에, 시계 방향과 반시계 방향 두 가지 길만 존재하는 점을 이용하여 두 방향 중 하나를 구하고 블록의 둘레의 50%와 비교하여 정답을 정하는게 핵심이었던 문제 같습니다. 상점과 동근이의 거리를 구할 때, (0,0)을 기준점으로 잡고 블록의 width, height, dist(상점이 기준점에서 떨어진 거리)를 조합하여 푸는 이 부분이 문제의 핵심인 것 같아요. |
||
| if dir == 1: # 북 | ||
| return dist | ||
| if dir == 2: # 남 | ||
| return w + h + (w - dist) | ||
| if dir == 3: # 서 | ||
| return 2*w + h + (h - dist) | ||
| if dir == 4: # 동 | ||
| return w + dist | ||
|
|
||
|
|
||
| # 4. 모든 상점의 위치를 1차원 조표로 변환해서 리스트에 모으기 | ||
| store_loc = [] # 상점의 위치 | ||
| for _ in range(store_cnt): | ||
| d, dist = map(int, input().split()) | ||
| store_loc.append(to_pos(d, dist)) | ||
|
|
||
| # 5. 경비원 위치도 똑같이 변환 | ||
| gd, gdist = map(int, input().split()) | ||
| guard_pos = to_pos(gd, gdist) | ||
|
|
||
| # print(f"store: {store_loc}") | ||
| # print(f"guard: {guard_pos}") | ||
|
|
||
| # 6. 각 상점까지 최단 거리 구해서 합산 | ||
| total = 0 | ||
| for store in store_loc: | ||
| diff = abs(store - guard_pos) | ||
| # 시계방향 <-> 반시계방향 중 짧은 거리 선택 | ||
| total += min(diff, perimeter - diff) | ||
|
|
||
| # 7. 결과 출력 | ||
| print(total) | ||
40 changes: 40 additions & 0 deletions
40
minjeong/Stack, Queue, Priority Queue/2025-05-10-[Programmers]-올바른괄호(JAVA).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,40 @@ | ||
| import java.util.*; | ||
|
|
||
| class Solution { | ||
| boolean solution(String s) { | ||
| // "(" 이면 stack에 push. ")"이면 stack에서 pop하기 | ||
| // stack의 길이가 0이면 true, stack의 길이가 1이상이면 false | ||
|
|
||
| // Stack ArrayList | ||
| ArrayList<Integer> stack = new ArrayList<>(); | ||
|
|
||
| // 문자열을 ArrayList로 변환 | ||
| String[] stringParam = s.split(""); | ||
| ArrayList<String> list = new ArrayList<String>(Arrays.asList(stringParam)); | ||
|
|
||
| // Stack Push & Pop | ||
| for (String str: stringParam){ | ||
| // System.out.println(str); | ||
| if (str.equals("(")) { | ||
| stack.add(0); | ||
| // System.out.println("추가 완료"); | ||
| } | ||
| else { | ||
| // 처음부터 ) 가 나올 경우 올바르지 않은 괄호 | ||
| if (stack.size() == 0){ | ||
| return false; | ||
| } | ||
| else { | ||
| stack.remove(stack.size() - 1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // 올바른 괄호가 아닐 경우 | ||
| if (stack.size() > 0) { | ||
| return false; | ||
| } | ||
| // 올바른 괄호가 아닌 경우 | ||
| return true; | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
minjeong/Stack, Queue, Priority Queue/2025-05-12-[Programmers]-기능개발-java.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,29 @@ | ||
| import java.util.*; | ||
|
|
||
| class Solution { | ||
| public int[] solution(int[] progresses, int[] speeds) { | ||
| ArrayList<Integer> answer = new ArrayList<>(); | ||
| ArrayList<Integer> queue = new ArrayList<>(); | ||
|
|
||
| for (int i=0; i < progresses.length; i++){ | ||
| int days = (int) Math.ceil((100.0 - progresses[i]) / speeds[i]); | ||
| if (queue.size() > 0 && days > queue.get(0)) { | ||
| answer.add(queue.size()); | ||
| queue.clear(); | ||
| queue.add(days); | ||
|
|
||
| } | ||
| else { | ||
| queue.add(days); | ||
| } | ||
| } | ||
| answer.add(queue.size()); | ||
|
|
||
| // 배열로 변환 | ||
| int[] arr = answer.stream() | ||
| .mapToInt(Integer::intValue) | ||
| .toArray(); | ||
|
|
||
| return arr; | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
minjeong/Stack, Queue, Priority Queue/2025-05-12-[Programmers]-프로세스-java.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,51 @@ | ||
| import java.util.*; | ||
|
|
||
| class Solution { | ||
| public int solution(int[] priorities, int location) { | ||
| // 1) 작업 큐: 인덱스(idx)와 우선순위(priority)를 함께 보관 | ||
| Queue<DTO> queue = new LinkedList<>(); | ||
|
|
||
| // 2) 우선순위 큐: 남아있는 작업 중 가장 높은 우선순위를 꺼내기 위함 | ||
| PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder()); | ||
|
|
||
| for (int i = 0 ; i < priorities.length; i++) { | ||
| queue.offer(new DTO(i, priorities[i])); | ||
| pq.offer(priorities[i]); | ||
| } | ||
|
|
||
| // System.out.println(queue); | ||
| // System.out.println(pq); | ||
|
|
||
| int count = 0; // 실행된 작업 수 | ||
|
|
||
| while(!queue.isEmpty()) { | ||
| DTO cur = queue.poll(); // 현재 작업 꺼냄 | ||
|
|
||
| // 현재 작업 우선순위가 남은 작업의 최고 우선순위와 같다면 | ||
| if(cur.priority == pq.peek()) { | ||
| count++; | ||
| pq.poll(); // 우선순위 큐에서 제거 | ||
| // 내가 찾던 작업이라면 실행 순서 반환 | ||
| if (cur.idx == location) { | ||
| return count; | ||
| } | ||
| } | ||
| else { | ||
| // 우선순위가 더 높은 작업이 남아있다면 뒤로 재삽입 | ||
| queue.offer(cur); | ||
| } | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| // 인덱스 + 우선순위를 함께 보관할 DTO | ||
| static class DTO { | ||
| int idx; | ||
| int priority; | ||
| DTO(int idx, int priority) { | ||
| this.idx = idx; | ||
| this.priority = priority; | ||
| // System.out.println("idx: "+idx+" priority: "+priority); | ||
| } | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
minjeong/Stack, Queue, Priority Queue/2025-05-14-[PGS]-같은숫자는싫어(java).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,25 @@ | ||
| import java.util.*; | ||
|
|
||
| public class Solution { | ||
| public int[] solution(int []arr) { | ||
| ArrayList<Integer> answer = new ArrayList<>(); | ||
|
|
||
| // 1. 첫 번째 값은 무조건 추가 | ||
| answer.add(arr[0]); | ||
|
|
||
| // 2. 두 번째 값부터 순차적으로 확인 | ||
| for (int i = 1; i < arr.length; i++) { | ||
| // 바로 이전 값과 다르면 추가 | ||
| if (answer.get(answer.size()-1) != arr[i]) { | ||
| answer.add(arr[i]); | ||
| } | ||
| } | ||
|
|
||
| // 3. ArrayList → int[] 변환 | ||
| int[] answer2 = new int[answer.size()]; | ||
| for (int i = 0; i < answer.size(); i++){ | ||
| answer2[i] = answer.get(i); | ||
| } | ||
| return answer2; | ||
| } | ||
| } |
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,16 @@ | ||
| import java.util.*; | ||
|
|
||
| class Solution { | ||
| public boolean solution(String[] phone_book) { | ||
|
|
||
| Arrays.sort(phone_book); // 오름차순 정렬 | ||
|
|
||
| for (int i = 0; i < phone_book.length - 1; i++ ) { | ||
| // 만약 다음 값이 현재 값으로 시작한다면, false 반환 | ||
| if (phone_book[i+1].startsWith(phone_book[i])) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| } |
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.
이번 문제는 시간복잡도가 넉넉해서 상관없긴 하지만,
이 문제는 민정님처럼 for문안에서 입력받기, 단축키 지정 두 가지를 한번에 하는 로직이 더 좋겠네요