- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1
[한종욱-19주차 알고리즘 스터디] #81
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
      
        
      
            Ukj0ng
  wants to merge
  93
  commits into
  main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
ukjong/week-19
  
      
      
   
  
    
  
  
  
 
  
      
    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
            
            
          Conversation
  
    
      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
    
  
  
    
    
    
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      
  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.
  
    
  
    
🚀 싸피 15반 알고리즘 스터디 19주차 [한종욱]
📌 문제 풀이 개요
✅ 문제 해결 여부
💡 풀이 방법
문제 1: 레이스
문제 난이도
Gold 2
문제 유형
이분 탐색, 매개변수 탐색
접근 방식 및 풀이
배치된 심판과의 거리를 이분 탐색으로 찾고, 해당 거리를 최소로 심판을 배치 할 수 있으면 거리를 더 늘려서 다음 거리를 탐색하는 방식으로 풀었습니다.
정렬했을 때, 가장 늦은 숫자를 선택해야 하기 때문에 심판을 앞에 세울 수 있다면 앞에 세워야 합니다.
시간복잡도:$O(k \times log(max_distance))$ 
문제 2: 중앙값 구하기
문제 난이도
Gold 2
문제 유형
자료구조, 우선순위
접근 방식 및 풀이
우선순위 큐를 두 개 사용해서, 중간값을 기준으로 중간값보다 큰 값만 담는 우선순위 큐와 중간값을 포함한 작은 값들을 담는 우선순위 큐를 사용합니다.
단 순서 상 중간값이기 high 우선순위 큐에도 중간값과 같은 값이 들어갈 수 있습니다.
중간값보다 큰 값인지 작은 값이지에 따라 high, low에 넣어주고 두 우선순위 큐의 균형을 맞춰줬습니다.
시간복잡도:$O(m \times log{m})$ 
문제 3: 물통
문제 난이도
Gold 2
문제 유형
BFS
접근 방식 및 풀이
물통에 물을 담는 방식을 BFS로 탐색했습니다. visited 배열에 "(물통A의 양),(물통B의 양)"의 형태로 저장해 중복 방문을 방지했습니다.
시간복잡도:$O(a \times b)$ 
문제 4: 로고
문제 난이도
Gold 2
문제 유형
분리 집합
접근 방식 및 풀이
사각형이 들어올 때마다, 기존 사각형과 비교해서 연결되어있는지를 판별합니다.
각 사각형을 분리 집합으로 판별해 총 몇 개의 묶음이 나오는지를 확인합니다.
시간복잡도:$O(n^{2})$ 
문제 5: 단어 섞기
문제 난이도
Gold 4
문제 유형
DP
접근 방식 및 풀이
두 문자열을 순서를 유지하면서 섞어서 세 번째 문자열을 만들 수 있는지 판단하는 문제입니다.
DP 테이블 dp[i][j]는 첫 번째 문자열의 처음 i글자와 두 번째 문자열의 처음 j글자를 사용해서 세 번째 문자열의 처음 (i+j)글자를 만들 수 있는지를 나타냅니다.
초기화:
dp[0][0] = true (빈 문자열로 빈 문자열 생성 가능)
첫 번째 행: 첫 번째 문자열만 사용하여 세 번째 문자열 생성 가능 여부
첫 번째 열: 두 번째 문자열만 사용하여 세 번째 문자열 생성 가능 여부
상태 전이:
현재 위치 dp[i][j]에서:
첫 번째 문자열의 i번째 문자가 세 번째 문자열의 (i+j)번째 문자와 같고, dp[i-1][j]가 true면 → dp[i][j] = true
두 번째 문자열의 j번째 문자가 세 번째 문자열의 (i+j)번째 문자와 같고, dp[i][j-1]이 true면 → dp[i][j] = true
최종적으로 dp[len1][len2]가 답이 됩니다.
시간복잡도:$O(n \times m)$