Skip to content

[2주차] 이지영 #17

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 9 commits into from
Sep 22, 2024
Merged

[2주차] 이지영 #17

merged 9 commits into from
Sep 22, 2024

Conversation

yeongleej
Copy link
Contributor

@yeongleej yeongleej commented Sep 16, 2024

📗 월요일

[CT] 예술성

🤔 시간복잡도 고려사항

시뮬레이션 문제, 특이사항 X

💡 풀이 아이디어

  • 예술점수 구하기 : BFS로 그룹과 인접 그룹 찾아 계산
  • 정사각형 회전
    : 정사각형이 4개가 생기는데, 각 정사각형의 시작점을 (0,0)으로 옮긴 뒤 회전 처리하고 다시 원래 위치로 복귀
        int size = N / 2;
        for(int i=sx; i<sx+size; i++){
            for(int j=sy; j<sy+size; j++){
                // (0, 0)으로 옮겨주기
                int ox = i-sx;
                int oy = j-sy;
                // x, y -> y, size-1-x
                int rx = oy;
                int ry = size-1-ox;
                nb[rx+sx][ry+sy] = board[i][j];
            }
        }

📗 화요일

[BOJ] 1647_도시 분할 계획

🤔 시간복잡도 고려사항

  • N: 집의 게수 <= 100,000
  • M: 길의 개수 <=1,000,000
    최대 O(M log M) 까지 가능 : 정렬, 다익스트라, 크루스칼 등등 생각해볼 수 있음

💡 풀이 아이디어

  • union-find를 활용한 크루스칼 알고리즘 적용
1. 간선을 비용에 따라 오름차순으로 정렬
2. 간선을 하나씩 확인하며 사이클 발생 여부 확인
- 사이클 발생 O : 최소신장트리에 포함 X
- 사이클 발생 X : 최소신장트리에 포함 O
3. 두 마을로 나눠야 하기 때문에 가장 마지막에 포함된(가장 큰 비용의 간선)을 제거

[SQL] 특정 물고기를 잡은 총 수 구하기

💡 풀이 아이디어

  • JOIN을 활용
  • WHERE 절에 조건 적용하기

📗 수요일

[BOJ] 2631_줄세우기

🤔 시간복잡도 고려사항

N<=200, 200 * 200

💡 풀이 아이디어

  • 가장증가하는부분수열(LIS) 활용
  • LIS를 제외한 나머지를 옮겨주면 됨

📗 목요일

[PG] 42584 주식가격

🤔 시간복잡도 고려사항

prices 길이 == N <= 100,000

💡 풀이 아이디어

  • 가격을 스택에 넣고, 스택의 상단과 비교
  • 스택의 상단 > 현재 가격 : 가격이 떨어짐, 시간기록

[PG] 42626 더 맵게

🤔 시간복잡도 고려사항

scoville 길이 <= 1,000,000 이므로 O(NlogN) or O(N) 생각

💡 풀이 아이디어

  • 가장 맵지 않은 스코빌 지수를 계속 확인하고 가져와야 하므로 "우선위큐" 사용
  • 우선순위 큐를 사용하면 O(logN)에 가져올 수 있음

[SQL] 물고기 종류별 대어 찾기

💡 풀이 아이디어

  • JOIN을 활용
  • 서브쿼리를 이용, IN 연산자 이용
    • 서브쿼리의 값인 (물고기 타입, 길이)와 일치하는 물고기를 select 해야 함

📗 금요일

[PG] 43163_단어변환

🤔 시간복잡도 고려사항

  • 각 단어길이 <= 10
  • words 길이 <= 50
    => 정점의 개수 (N) == words 길이, 즉 O(N^2)이어도 괜찮음
    => 완전탐색 고려(BFS, DFS 등)

💡 풀이 아이디어

  • BFS로 풀이
  • 현재 단어(now)와 다음 탐색할 단어(next)가 하나의 알파벳만 차이나면 해당 단어로 이동할 수 있음 => 큐에 삽입

[PG] 12913_땅따먹기

🤔 시간복잡도 고려사항

  • N <= 100,000
  • 완전탐색(DFS, BFS)로 풀려면, O(N^2)이므로 시간초과
  • DP를 활용 => O(N * 4)로 해결 가능

💡 풀이 아이디어

  • 현재 land[i][j]일 때, 이전 행인 land[i-1]에서 j열과 같지 않은 것을 골라 합했을 때 최댓값을 갱신
  • 점화식
dp[i][j] = max(dp[i][j], dp[i-1][k])  // j != k

bfs,dfs 탐색 시간복잡도가 O(N*E)인 줄알고 시간초과가 나는 이유를 몰랐습니다... 다시보니 N이 충분히 크고 dp로 풀면 될 것 같았습니다

nb[N-j-1][N/2] = board[N/2][j];
}
}
public static void turnBox(int sx, int sy) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전 회전에서 어려움이 많았는데 깔끔하게 푸셨네요!!
코드리뷰때 해설 기대하겠습니다...!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

회전 구현 너무 어려웠는데 저도 기대하겠습니다..🫥

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

222222,,,,

for(int j=0; j<4; j++) {
for(int k = 0; k<4; k++){
if(j != k){
dp[i][j] = Math.max(dp[i][j], dp[i-1][k]+land[i][j]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

직관적이라서 보기 좋아요!

nb[N-j-1][N/2] = board[N/2][j];
}
}
public static void turnBox(int sx, int sy) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

회전 구현 너무 어려웠는데 저도 기대하겠습니다..🫥

@baexxbin baexxbin merged commit 67246b8 into GreatAlgorithm-Study:main Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants