Skip to content

[정민서-15주차 알고리즘 스터디] #26

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
wants to merge 50 commits into
base: minseojeong/week15
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
9991dc1
[Baekjoon-1193] 분수찾기
minseojeong1012 Feb 16, 2025
3c7b000
[Baekjoon-2563] 색종이
minseojeong1012 Feb 16, 2025
1a3291d
[Baekjoon-3711] 학번
minseojeong1012 Feb 16, 2025
afa680b
[Baekjoon-4108] 지뢰찾기
minseojeong1012 Feb 16, 2025
65b2931
Update README.md
minseojeong1012 Feb 16, 2025
c5e7776
[Baekjoon-1181] 단어정렬
minseojeong1012 Feb 16, 2025
af37ef6
Merge branch 'main' of https://github.com/minseojeong1012/Algorithm-s…
minseojeong1012 Feb 16, 2025
ebad716
Update README.md
minseojeong1012 Feb 16, 2025
d6268a4
[Baekjoon-4659] 비밀번호 발음하기
minseojeong1012 Feb 23, 2025
916e5ce
Merge branch 'main' of https://github.com/minseojeong1012/Algorithm-s…
minseojeong1012 Feb 23, 2025
4a9fc84
[Baekjoon-25757] 임스와 함께하는 미니게임
minseojeong1012 Feb 25, 2025
4d55f3c
[Baekjoon-20125] 쿠키의 신체측정
minseojeong1012 Feb 25, 2025
e3cf666
[Baekjoon-1205] 등수 구하기
minseojeong1012 Feb 25, 2025
11fa378
[Baekjoon-1244] 스위치 켜고 끄기
minseojeong1012 Feb 25, 2025
f754477
[Baekjoon-1094] 막대기
minseojeong1012 Mar 2, 2025
0df464b
[Baekjoon-11053] 가장 긴 증가하는 부분 수열
minseojeong1012 Mar 2, 2025
3147626
[Baekjoon-6603] 로또
minseojeong1012 Mar 2, 2025
8133071
[Baejoon-15651] N과 M(3)
minseojeong1012 Mar 2, 2025
8179836
[Baekjoon-15652] N과 M(4)
minseojeong1012 Mar 11, 2025
5d812de
[Baekjoon-15654] N과 M (5)
minseojeong1012 Mar 11, 2025
36ff70a
[Baekjoon-15655] N과 M (6)
minseojeong1012 Mar 11, 2025
a5d33b3
[Baekjoon-1759] 암호 만들기
minseojeong1012 Mar 11, 2025
42b74c3
[Baekjoon-16938] 캠프 준비
minseojeong1012 Mar 11, 2025
2f9cbab
[Baekjoon-15663] N과 M (9)
minseojeong1012 Mar 19, 2025
d7b7dc7
[Baekjoon-11725] 트리의 부모 찾기
minseojeong1012 Mar 19, 2025
1ffe2dd
[Baekjoon-11660] 구간 합 구하기 5
minseojeong1012 Mar 19, 2025
8b088eb
[Baekjoon-5639] 이진 검색 트리
minseojeong1012 Mar 19, 2025
4822810
[Baekjoon-1012] 유기농 배추
minseojeong1012 Mar 23, 2025
4361fee
[Baekjoon-1260] DFS와 BFS
minseojeong1012 Mar 23, 2025
05a8394
[Baekjoon-1697] 숨바꼭질
minseojeong1012 Mar 23, 2025
86b07f3
[Baekjoon-10026] 적록색약
minseojeong1012 Mar 23, 2025
da0a030
[Baekjoon-11404] 플로이드
minseojeong1012 Mar 23, 2025
f1390ee
Update README.md
minseojeong1012 Mar 25, 2025
9eab08d
[Baekjoon-1238] 파티
minseojeong1012 Mar 30, 2025
d615032
[Baekjoon-1197] 최소 스패닝 트리
minseojeong1012 Mar 30, 2025
7ae6c74
[Baekjoon-14940] 쉬운 최단거리
minseojeong1012 Mar 30, 2025
e8459e9
[Baekjoon-11403] 경로 찾기
minseojeong1012 Mar 30, 2025
b13cf2b
[Baekjoon-16928] 뱀과 사다리 게임
minseojeong1012 Mar 30, 2025
1ed575a
[Baekjoon-11727] 2xn 타일링2
minseojeong1012 Apr 6, 2025
92acc7a
[Baekjoon-11727] 2xn 타일링2
minseojeong1012 Apr 6, 2025
1d370e9
Merge branch 'main' of https://github.com/minseojeong1012/Algorithm-s…
minseojeong1012 Apr 6, 2025
2e3a051
[Baekjoon-1261] 알고스팟
minseojeong1012 Apr 6, 2025
e4998d0
[Baekjoon-9251] LCS
minseojeong1012 Apr 6, 2025
a495cb5
[Baekjoon-12865] 평범한 배낭
minseojeong1012 Apr 6, 2025
ebd9f3e
[Baekjoon-2293] 동전1
minseojeong1012 Apr 13, 2025
4d40cfb
Merge branch 'main' of https://github.com/minseojeong1012/Algorithm-s…
minseojeong1012 Apr 13, 2025
28721b7
13주차
minseojeong1012 Apr 20, 2025
d297d29
14주차 완료
minseojeong1012 Apr 27, 2025
74c5380
15주차
minseojeong1012 May 6, 2025
62ffcf6
16주차 완료
minseojeong1012 May 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/algo.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Algorithm-study-3
Submodule Algorithm-study-3 added at a495cb
87 changes: 66 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- 공통 문제 마감 시간 : 매 주 일요일 23시 59분
- 마감 시간 전까지 해당 주차 5문제을 풀이하여 개인 브랜치에 업로드하고, PR을 제출합니다.
- 각 카테고리에 맞게, 매주 5문제의 공통 문제가 주어집니다.
- 난이도는 Bronze ~ Silver 문제 입니다.
- 난이도는 Silver ~ Gold 문제 입니다.
- PR에 다른 사람의 풀이를 보고 적극적인 커멘트를 남겨주세요

## 🗓️ 파일구조는 다음예시처럼 해주세요
Expand All @@ -14,34 +14,79 @@
- main에 푸쉬하는 것을 금지합니다 (전부 날라갈 위험이 있음!!)
- 브랜치명은 다음과 같은 규칙을 지켜주세요!! ex) 이름/week-1, d11210920/week-1
- 이슈는 따로 생성하지 않으셔도 됩니다!! 다만 , PR template을 작성하고 카테고리,제목,링크만 제대로 연결시키고 자신의 README에 추가해주세요
## ❗️ PR 규칙 및 Commit Message 규칙 ❗️
### [김동하-1주차 알고리즘 스터디]
#### Week 01 (25.01.20 ~ 25.01.27)
| Category | Title | Link |
| :------: | :---: | :--: |
| 그래프 | <a href="https://www.acmicpc.net/problem/17472">다리만들기 2</a> | <a href="">🔗</a> |
| BFS | <a href="https://www.acmicpc.net/problem/22856">게리맨더링</a> | <a href="">🔗</a> |
| 완탐 | <a href="https://www.acmicpc.net/problem/17070">파이프 옮기기 1</a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/2578">빙고</a> | <a href="">🔗</a> |
| DP | <a href="https://www.acmicpc.net/problem/10844">쉬운 계단 수</a> | <a href="">🔗</a> |
<br>

```
To. Reviewers
```
### Commit Message
[Baekjoon-문제번호] 문제명


## 주차 별 문제풀이
https://github.com/tony9402/baekjoon && https://www.acmicpc.net/group/workbook/22697

### Week 10 (25.03.24 ~ 25.03.31)
| Category | Title | Link |
| :------: | :---: | :--: |
| 그래프 | <a href="https://www.acmicpc.net/problem/1197">최소 스패닝 트리</a> | <a href="">🔗</a> |
| 그래프 | <a href="https://www.acmicpc.net/problem/1238">파티 | <a href="">🔗</a> |
| 그래프 | <a href="https://www.acmicpc.net/problem/14940">쉬운 최단거리</a> | <a href="">🔗</a> |
| 그래프 | <a href="https://www.acmicpc.net/problem/11403">경로찾기</a> | <a href="">🔗</a> |
| 그래프 | <a href="https://www.acmicpc.net/problem/16928">뱀과 사다리 게임 </a> | <a href="">🔗</a> |
<br>

### Week 09 (25.03.17 ~ 25.03.23)
| Category | Title | Link |
| :------: | :---: | :--: |
| 그래프 | <a href="https://www.acmicpc.net/problem/1012">유기농 배추</a> | <a href="">🔗</a> |
| 그래프 | <a href="https://www.acmicpc.net/problem/1260">DFS와 BFS| <a href="">🔗</a> |
| 그래프 | <a href="https://www.acmicpc.net/problem/1697">숨바꼭질</a> | <a href="">🔗</a> |
| 그래프 | <a href="https://www.acmicpc.net/problem/10026">적록색약</a> | <a href="">🔗</a> |
| 그래프 | <a href="https://www.acmicpc.net/problem/11404">플로이드 </a> | <a href="">🔗</a> |
<br>

### Week 08 (25.03.10 ~ 25.03.16)
| Category | Title | Link |
| :------: | :---: | :--: |
| 백트래킹 | <a href="https://www.acmicpc.net/problem/15663">N과 M (9)</a> | <a href="">🔗</a> |
| 그래프 | <a href="https://www.acmicpc.net/problem/11725">트리의 부모 찾기| <a href="">🔗</a> |
| DP | <a href="https://www.acmicpc.net/problem/11660">구간 합 구하기 5</a> | <a href="">🔗</a> |
| 그래프 | <a href="https://www.acmicpc.net/problem/5639">이진 검색 트리</a> | <a href="">🔗</a> |
| 그래프 | <a href="https://www.acmicpc.net/problem/1753">최단경로 </a> | <a href="">🔗</a> |
<br>

### Week 07 (25.03.04 ~ 25.03.09)
| Category | Title | Link |
| :------: | :---: | :--: |
| 백트래킹 | <a href="https://www.acmicpc.net/problem/15652">N과 M (4)</a> | <a href="">🔗</a> |
| 백트래킹 | <a href="https://www.acmicpc.net/problem/15654">N과 M (5) | <a href="">🔗</a> |
| 백트래킹 | <a href="https://www.acmicpc.net/problem/15655">N과 M (6)</a> | <a href="">🔗</a> |
| 백트래킹 | <a href="https://www.acmicpc.net/problem/1759">암호 만들기</a> | <a href="">🔗</a> |
| 백트래킹 | <a href="https://www.acmicpc.net/problem/16938">캠프 준비 </a> | <a href="">🔗</a> |
<br>

### Week 06 (25.02.25 ~ 25.03.03)
| Category | Title | Link |
| :------: | :---: | :--: |
| 구현 | <a href="https://www.acmicpc.net/problem/1094">막대</a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/11053">가장 긴 증가하는 부분수열</a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/6603">로또 </a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/15651">N과 M (3)</a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/1074">Z </a> | <a href="">🔗</a> |
<br>

### Week 05 (25.02.17 ~ 25.02.24)
| Category | Title | Link |
| :------: | :---: | :--: |
| 구현 | <a href="https://www.acmicpc.net/problem/4659">비밀번호 발음하기</a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/25757">임스와 함께하는 미니게임</a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/20125">쿠키의 신체측정 </a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/1205">등수 구하기</a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/1244">스위치 켜고 끄기 </a> | <a href="">🔗</a> |
<br>

### Week 04 (25.02.10 ~ 25.02.17)
| Category | Title | Link |
| :------: | :---: | :--: |
| 수학 | <a href="https://www.acmicpc.net/problem/1110">더하기 사이클</a> | <a href="">🔗</a> |
| 완탐 | <a href="https://www.acmicpc.net/problem/1145">적어도 대부분 배수</a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/2846">오르막길</a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/3085">사탕 게임</a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/2851">슈퍼 마리오</a> | <a href="">🔗</a> |
| 수학 | <a href="https://www.acmicpc.net/problem/1193">분수찾기</a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/2563">색종이</a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/3711">학번 </a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/1181">단어 정렬</a> | <a href="">🔗</a> |
| 구현 | <a href="https://www.acmicpc.net/problem/4108">지뢰찾기 </a> | <a href="">🔗</a> |
<br>
38 changes: 38 additions & 0 deletions 정민서/10주차/[Baekjoon-11403] 경로 찾기.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.io.*;
import java.util.*;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[][] graph = new int[n][n];

for (int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
for (int j = 0; j < n; j++) {
graph[i][j] = Integer.parseInt(st.nextToken());
}
}

for (int k = 0; k < n; k++) { // 중간 정점
for (int i = 0; i < n; i++) { // 시작 정점
for (int j = 0; j < n; j++) { // 도착 정점
// k를 거쳐서 i에서 j로 갈 수 있다면 경로 존재 표시
if (graph[i][k] == 1 && graph[k][j] == 1) {
graph[i][j] = 1;
}
}
}
}

// 결과 출력
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
sb.append(graph[i][j]).append(" ");
}
sb.append("\n");
}
System.out.print(sb);
}
}
97 changes: 97 additions & 0 deletions 정민서/10주차/[Baekjoon-1197] 최소 스패닝 트리.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.StringTokenizer;


public class Main {

static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static final StringBuilder sb = new StringBuilder("");

static int n,m;
static Edge[] edgelist;
static int[] parents;

static class Edge implements Comparable<Edge>{
int from, to, w;

public Edge(int from, int to, int w) {
super();
this.from = from;
this.to = to;
this.w = w;
}

@Override
public int compareTo(Edge e) {
return Integer.compare(this.w, e.w);
}
}

public static void main(String[] args)throws IOException {
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());

edgelist = new Edge[m];
for (int i = 0; i < m; i++) {

st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());

edgelist[i] = new Edge(a,b,c);
}

Arrays.sort(edgelist);

parents = new int[n + 1];
for (int i = 1; i <= n; i++) {
parents[i] = i;
}

int result = 0, count = 0;
for (Edge e : edgelist) {

if (union(e.from, e.to)) {
result += e.w;
if (++count == n-1) {
break;
}
}
}

System.out.println(result);
}

static boolean union(int a, int b) {
int aRoot = find(a);
int bRoot = find(b);

if (aRoot == bRoot) {
return false;
}

if (aRoot>bRoot) {
parents[bRoot] = aRoot;
} else {
parents[aRoot] = bRoot;
}
return true;
}

static int find(int a) {

if (a == parents[a]) {
return a;
}
return parents[a] = find(parents[a]);
}

}
85 changes: 85 additions & 0 deletions 정민서/10주차/[Baekjoon-1238] 파티.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import java.io.*;
import java.util.*;

public class Main {
// 간선 정보를 저장하는 클래스
static class Edge implements Comparable<Edge> {
int to, weight;
public Edge(int to, int weight) {
this.to = to;
this.weight = weight;
}
public int compareTo(Edge o) {
return this.weight - o.weight;
}
}

// 다익스트라 알고리즘 구현
public static int[] dijkstra(int start, List<Edge>[] graph, int n) {
int INF = Integer.MAX_VALUE;
int[] dist = new int[n + 1];
Arrays.fill(dist, INF);
dist[start] = 0;
PriorityQueue<Edge> pq = new PriorityQueue<>();
pq.offer(new Edge(start, 0));

while (!pq.isEmpty()) {
Edge current = pq.poll();
int currentNode = current.to;
int currentWeight = current.weight;

if (currentWeight > dist[currentNode]) continue;

for (Edge edge : graph[currentNode]) {
int next = edge.to;
int nextCost = currentWeight + edge.weight;
if (nextCost < dist[next]) {
dist[next] = nextCost;
pq.offer(new Edge(next, nextCost));
}
}
}
return dist;
}

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int x = Integer.parseInt(st.nextToken());

// 그래프와 역방향 그래프 초기화
List<Edge>[] graph = new ArrayList[n + 1];
List<Edge>[] reverseGraph = new ArrayList[n + 1];
for (int i = 1; i <= n; i++) {
graph[i] = new ArrayList<>();
reverseGraph[i] = new ArrayList<>();
}

for (int i = 0; i < m; i++) {
st = new StringTokenizer(br.readLine());
int u = Integer.parseInt(st.nextToken());
int v = Integer.parseInt(st.nextToken());
int w = Integer.parseInt(st.nextToken());
// 정방향 그래프
graph[u].add(new Edge(v, w));
// 역방향 그래프 (각 간선의 방향을 반대로)
reverseGraph[v].add(new Edge(u, w));
}

// X에서 각 노드로 가는 최단 경로 (X → i)
int[] distFromX = dijkstra(x, graph, n);
// 각 노드에서 X로 가는 최단 경로 (i → X)
int[] distToX = dijkstra(x, reverseGraph, n);

// 각 노드별 왕복 시간 중 최댓값 계산
int maxTime = 0;
for (int i = 1; i <= n; i++) {
maxTime = Math.max(maxTime, distToX[i] + distFromX[i]);
}

System.out.println(maxTime);
}
}
Loading