diff --git a/.gitignore b/.gitignore index 73dcb74..b9f4630 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .DS_Store .idea/ /.vscode +cmake-build-debug/ +CMakeLists.txt \ No newline at end of file diff --git a/g0rnn/DFS,BFS/12-g0rnn.cpp b/g0rnn/DFS,BFS/12-g0rnn.cpp new file mode 100644 index 0000000..3854189 --- /dev/null +++ b/g0rnn/DFS,BFS/12-g0rnn.cpp @@ -0,0 +1,81 @@ +// +// Created by 김균호 on 2025. 1. 2.. +// +#include +#include +#include +using namespace std; + +#define FRIEND 1 + +int n; +int club[55][55]; +vector president; +// 첫번째 인자 기준 +//priority_queue, vector >, greater<> > candidate; + +int bfs(int a) { + queue q; + vector visited(n + 1, false); + int point = -1; + q.push(a); + visited[a] = true; + + while (!q.empty()) { + size_t size = q.size(); + + for (int _ = 0; _ < size; _++) { + int k = q.front(); + q.pop(); + for (int i = 1; i <= n; i++) { + if (k != i && !visited[i] && club[k][i] == FRIEND) { + visited[i] = true; + q.push(i); + } + } + } + point++; + } + return point; +} + +int main() { + cin >> n; + int a, b; + while (true) { + cin >> a >> b; + if (a == -1 && b == -1) break; + club[a][b] = FRIEND; + club[b][a] = FRIEND; + } + /* + for (int i = 1; i <= n; i++) { + int score = bfs(i); + candidate.emplace(score,i); + } + + auto [point, who] = candidate.top(); + candidate.pop(); + president.push_back(who); + + while (candidate.top().first == point) { + president.push_back(candidate.top().second); + candidate.pop(); + }*/ + + int min_point = INT_MAX; + for (int i = 1; i <= n; i++) { + int score = bfs(i); + if (score < min_point) { + min_point = score; + president.clear(); + president.push_back(i); + } else if (score == min_point) { + president.push_back(i); + } + } + + cout << min_point << ' ' << president.size() << '\n'; + for (int i: president) cout << i << ' '; + return 0; +} diff --git a/g0rnn/README.md b/g0rnn/README.md index f8dcc1e..39441b4 100644 --- a/g0rnn/README.md +++ b/g0rnn/README.md @@ -1,15 +1,19 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -| :---: | :--------: | :--------: | :---------------------------------------------------------------------------: | :-------------------------------------------------: | -| 1차시 | 2024.10.01 | 구현 | [추억 점수](https://school.programmers.co.kr/learn/courses/30/lessons/176963) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/35 | -| 2차시 | 2024.10.03 | 트리 | [LCA2](https://school.programmers.co.kr/learn/courses/30/lessons/176963) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/7 | -| 3차시 | 2024.10.04 | 문자열 | [잃어버린 괄호](https://www.acmicpc.net/problem/1541) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/9 | -| 4차시 | 2024.10.11 | 브루트포스 | [영화감독 숌](https://www.acmicpc.net/problem/1436) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/15 | -| 5차시 | 2024.11.01 | BFS/DFS | [연구소](https://www.acmicpc.net/problem/14502) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/17 | -| 6차시 | 2024.11.06 | 구현 | [통계학](https://www.acmicpc.net/problem/2108) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/23 | -| 7차시 | 2024.11.25 | 구현 | [팰린드롬 만들기](https://www.acmicpc.net/problem/1213) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/31 | -| 8차시 | 2024.11.29 | 문자열 | [잠수함식별](https://www.acmicpc.net/problem/2671) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/35 | -| 9차시 | 2024.12.04 | 그리디 | [A->B](https://www.acmicpc.net/problem/16953) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/39 | +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | +|:----:|:----------:|:-------:|:-------------------------------------------------------------------------:|:---------------------------------------------------:| +| 1차시 | 2024.10.01 | 구현 | [추억 점수](https://school.programmers.co.kr/learn/courses/30/lessons/176963) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/35 | +| 2차시 | 2024.10.03 | 트리 | [LCA2](https://school.programmers.co.kr/learn/courses/30/lessons/176963) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/7 | +| 3차시 | 2024.10.04 | 문자열 | [잃어버린 괄호](https://www.acmicpc.net/problem/1541) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/9 | +| 4차시 | 2024.10.11 | 브루트포스 | [영화감독 숌](https://www.acmicpc.net/problem/1436) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/15 | +| 5차시 | 2024.11.01 | BFS/DFS | [연구소](https://www.acmicpc.net/problem/14502) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/17 | +| 6차시 | 2024.11.06 | 구현 | [통계학](https://www.acmicpc.net/problem/2108) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/23 | +| 7차시 | 2024.11.25 | 구현 | [팰린드롬 만들기](https://www.acmicpc.net/problem/1213) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/31 | +| 8차시 | 2024.11.29 | 문자열 | [잠수함식별](https://www.acmicpc.net/problem/2671) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/35 | +| 9차시 | 2024.12.04 | 그리디 | [A->B](https://www.acmicpc.net/problem/16953) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/39 | +| 10차시 | 2024.12.20 | 그래프 | [결혼식](https://www.acmicpc.net/problem/5567) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/40 | +| 11차시 | 2024.12.30 | dp | [기타리스트](https://www.acmicpc.net/problem/1495) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/49 | +| 12차시 | 2025.01.02 | bfs | [회장뽑기](https://www.acmicpc.net/problem/2660) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/50 | + --- diff --git a/g0rnn/dp/11-g0rnn.cpp b/g0rnn/dp/11-g0rnn.cpp new file mode 100644 index 0000000..4ff7d28 --- /dev/null +++ b/g0rnn/dp/11-g0rnn.cpp @@ -0,0 +1,38 @@ +// +// Created by 김균호 on 2024. 12. 31.. +// +// 1. 조절한 볼륨이 0보다 작거나 max보다 크면 연주할 수 없다 -> -1 +// 2. 범위 내의 최댓값을 구하라 + +#include +using namespace std; + +int n, s, m; +int v[55]; +bool dp[55][1005]; +int ans = -1; + +int main() { + cin >> n >> s >> m; + for (int i = 1; i <= n; i++) + cin >> v[i]; + + if (s + v[1] <= m) dp[1][s + v[1]] = true; + if (s - v[1] >= 0) dp[1][s - v[1]] = true; + + for (int i = 2; i <= n; i++) { + for (int j = 0; j <= m; j++) { + if (!dp[i - 1][j]) continue; + if (j + v[i] <= m) dp[i][j + v[i]] = true; + if (j - v[i] >= 0) dp[i][j - v[i]] = true; + } + } + for (int i = m; i >= 0; i--) { + if (dp[n][i]) { + ans = i; + break; + } + } + cout << ans; + return 0; +} diff --git a/g0rnn/graph/10-g0rnn.cpp b/g0rnn/graph/10-g0rnn.cpp new file mode 100644 index 0000000..45664a3 --- /dev/null +++ b/g0rnn/graph/10-g0rnn.cpp @@ -0,0 +1,38 @@ +// +// Created by 김균호 on 2024. 12. 20.. +// +#include +#include +#include +using namespace std; + +const int SANG = 1; +int n, m; +int ret = 0; +vector > relationship; +unordered_set members = {1}; + +int main() { + cin >> n >> m; + relationship = vector >(n + 1); + int a, b; + + for (int i = 0; i < m; i++) { + cin >> a >> b; + // + if (a == SANG) members.insert(b); + // make a graph + relationship[a].insert(b); + relationship[b].insert(a); + } + + // find friends' friends + for (auto f: relationship[SANG]) { + for (auto r: relationship[f]) { + members.insert(r); + } + } + + // exclude SANG + cout << members.size() - 1; +} diff --git a/kangrae-jo/Graph/13-kangrae-jo.cpp b/kangrae-jo/Graph/13-kangrae-jo.cpp new file mode 100644 index 0000000..5397f1e --- /dev/null +++ b/kangrae-jo/Graph/13-kangrae-jo.cpp @@ -0,0 +1,47 @@ +#include +#include +#include + +using namespace std; + +int N, M; +vector visited; +vector> graph; + +void dfs(int v, list& r) { + visited[v] = true; + for (int x : graph[v]) { + if (visited[x] == false) dfs(x, r); + } + r.push_front(v); +} + +list topologicalSort() { + list r; + for (int v = 1; v <= N; v++) { + if (visited[v] == false) dfs(v, r); + } + + return r; +} + +int main() { + cin >> N >> M; + + visited = vector(N + 1, false); + graph = vector>(N + 1); + + while (M--) { + int a, b; + cin >> a >> b; + + graph[a].push_back(b); + } + + list r = topologicalSort(); + for (int i : r) { + cout << i << " "; + } + + return 0; +} diff --git a/kangrae-jo/Greedy/11-kangrae-jo.cpp b/kangrae-jo/Greedy/11-kangrae-jo.cpp new file mode 100644 index 0000000..fabfbc4 --- /dev/null +++ b/kangrae-jo/Greedy/11-kangrae-jo.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +using namespace std; + +int main() { + int N; + cin >> N; + + vector ATM(N); + for (int i = 0; i < N; i++) { + cin >> ATM[i]; + } + + sort(ATM.begin(), ATM.end()); + + int result = 0; + for (int wait = 0; wait < N; wait++) { + for (int use = 0; use <= wait; use++) { + result += ATM[use]; + } + } + + cout << result; + + return 0; +} \ No newline at end of file diff --git a/kangrae-jo/HEAP/12-kangrae-jo.cpp b/kangrae-jo/HEAP/12-kangrae-jo.cpp new file mode 100644 index 0000000..37ebb1b --- /dev/null +++ b/kangrae-jo/HEAP/12-kangrae-jo.cpp @@ -0,0 +1,37 @@ +#include +#include + +using namespace std; + +priority_queue pq; + +void base(int gift) { + int temp; + while (gift--) { + cin >> temp; + pq.push(temp); + } +} + +void meet() { + if (pq.empty()) cout << -1 << '\n'; + else { + cout << pq.top() << '\n'; + pq.pop(); + } +} + +int main() { + int n; + cin >> n; + + int temp; + while (n--) { + cin >> temp; + + if (temp == 0) meet(); + else base(temp); + } + + return 0; +} diff --git a/kangrae-jo/README.md b/kangrae-jo/README.md index 2fa012c..3fd6751 100644 --- a/kangrae-jo/README.md +++ b/kangrae-jo/README.md @@ -8,10 +8,13 @@ | 4차시 | 2024.10.05 | BFS | [아이템 줍기](https://school.programmers.co.kr/learn/courses/30/lessons/87694)|[#12](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/12)| | 5차시 | 2024.11.02 | DP | [경쟁 배타의 원리](https://level.goorm.io/exam/162070/%EA%B2%BD%EC%9F%81-%EB%B0%B0%ED%83%80%EC%9D%98-%EC%9B%90%EB%A6%AC/quiz/1)|[#18](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/18)| | 6차시 | 2024.11.05 | Greedy | [단속카메라](https://school.programmers.co.kr/learn/courses/30/lessons/42884)| [#21](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/21)| -| 7차시 | 2024.11.09 | DP | [1로 만들기](https://www.acmicpc.net/problem/1463)|[#12](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/24)| +| 7차시 | 2024.11.09 | DP | [1로 만들기](https://www.acmicpc.net/problem/1463)|[#24](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/24)| | 8차시 | 2024.11.12 | HEAP | [더 맵게](https://school.programmers.co.kr/learn/courses/30/lessons/42626)|[#27](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/27)| | 9차시 | 2024.11.23 | DP | [정수 삼각형](https://school.programmers.co.kr/learn/courses/30/lessons/43105)|[#30](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/30)| -| 10차시 | 2024.11.30 | 누적합 | [구간 합 구하기 4](https://www.acmicpc.net/problem/11659)|[#18](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/37)| +| 10차시 | 2024.11.30 | 누적합 | [구간 합 구하기 4](https://www.acmicpc.net/problem/11659)|[#37](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/37)| +| 11차시 | 2024.12.21 | Greedy | [ATM](https://www.acmicpc.net/problem/11399)|[#41](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/41)| +| 12차시 | 2024.12.24 | HEAP | [크리스마스 선물](https://www.acmicpc.net/problem/14235)|[#44](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/44)| +| 13차시 | 2024.12.28 | Graph | [줄 세우기](https://www.acmicpc.net/problem/2252)|[#46](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/46)| | 14차시 | 2024.12.31 | Two Pointer | [두 용액](https://www.acmicpc.net/problem/2470)|[#48](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/48)| ---- \ No newline at end of file +--- diff --git a/kokeunho/README.md b/kokeunho/README.md index 351dac3..15eb65a 100644 --- a/kokeunho/README.md +++ b/kokeunho/README.md @@ -11,4 +11,7 @@ | 7차시 | 2024.11.12 | 구현 | [치킨 배달](https://www.acmicpc.net/problem/15686) | [#25](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/25) | | 8차시 | 2024.11.17 | 구현 | [인구 이동](https://www.acmicpc.net/problem/16234) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/28) | | 9차시 | 2024.11.26 | 다이나믹 프로그래밍 | [계단 오르기](https://www.acmicpc.net/problem/2579) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/33) | +| 10차시 | 2024.11.30 | 자료구조 | [가운데를 말해요](https://www.acmicpc.net/problem/1655) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/36) | +| 11차시 | 2024.12.21 | 그리디 알고리즘 | [회의실 배정](https://www.acmicpc.net/problem/1931) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/43) | +| 12차시 | 2024.12.25 | 그리디 알고리즘 | [크게 만들기](https://www.acmicpc.net/problem/2812) | [#45](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/45) | --- diff --git "a/kokeunho/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/11-kokeunho.java" "b/kokeunho/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/11-kokeunho.java" new file mode 100644 index 0000000..b61e488 --- /dev/null +++ "b/kokeunho/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/11-kokeunho.java" @@ -0,0 +1,34 @@ +package org.example; + +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int[][] meetings = new int[n][2]; + + for (int i = 0; i < n; i++) { + meetings[i][0] = sc.nextInt(); + meetings[i][1] = sc.nextInt(); + } + + Arrays.sort(meetings, (a, b) -> { + if (a[1] == b[1]) { + return Integer.compare(a[0], b[0]); + } + return Integer.compare(a[1], b[1]); + }); + + int count = 0; + int lastEnd = 0; + + for (int i = 0; i < n; i++) { + if (meetings[i][0] >= lastEnd) { + count++; + lastEnd = meetings[i][1]; + } + } + System.out.println(count); + } +} \ No newline at end of file diff --git "a/kokeunho/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/12-kokeunho.java" "b/kokeunho/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/12-kokeunho.java" new file mode 100644 index 0000000..836d1ef --- /dev/null +++ "b/kokeunho/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/12-kokeunho.java" @@ -0,0 +1,32 @@ +package org.example; + +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int k = sc.nextInt(); + String num = sc.next(); + + Stack stack = new Stack<>(); + + int count = 0; + + for(int i = 0; i < n; i++) { + char c = num.charAt(i); + while(!stack.isEmpty() && count < k && stack.peek() < c) { + stack.pop(); + count++; + } + stack.push(c); + } + + StringBuilder result = new StringBuilder(); + for(int i = 0; i < n - k; i++) { + result.append(stack.get(i)); + } + System.out.println(result.toString()); + + } +} \ No newline at end of file diff --git "a/kokeunho/\354\236\220\353\243\214\352\265\254\354\241\260/10-kokeunho.java" "b/kokeunho/\354\236\220\353\243\214\352\265\254\354\241\260/10-kokeunho.java" new file mode 100644 index 0000000..097b969 --- /dev/null +++ "b/kokeunho/\354\236\220\353\243\214\352\265\254\354\241\260/10-kokeunho.java" @@ -0,0 +1,35 @@ +package org.example; + +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + StringBuilder sb = new StringBuilder(); + + int n = sc.nextInt(); + + PriorityQueue maxHeap = new PriorityQueue<>(Collections.reverseOrder()); + PriorityQueue minHeap = new PriorityQueue<>(); + + for (int i = 0; i < n; i++) { + int num = sc.nextInt(); + + if (maxHeap.size() <= minHeap.size()) { + maxHeap.offer(num); + } else { + minHeap.offer(num); + } + + if (!minHeap.isEmpty() && maxHeap.peek() > minHeap.peek()) { + int little = minHeap.poll(); + int big = maxHeap.poll(); + + maxHeap.offer(little); + minHeap.offer(big); + } + sb.append(maxHeap.peek()).append("\n"); + } + System.out.println(sb); + } +} \ No newline at end of file diff --git "a/wnsmir/BFS/DFS/\353\257\270\353\241\234\355\203\210\354\266\234.py" "b/wnsmir/BFS/DFS/\353\257\270\353\241\234\355\203\210\354\266\234.py" new file mode 100644 index 0000000..ba82c5b --- /dev/null +++ "b/wnsmir/BFS/DFS/\353\257\270\353\241\234\355\203\210\354\266\234.py" @@ -0,0 +1,34 @@ +from collections import deque + +N, M = map(int, input().split()) +graph = [] + +for i in range(N): + graph.append(list(map(int, input()))) + +dx = [-1, 1, 0, 0] +dy = [0, 0, -1, 1] + +def bfs(x, y): + queue = deque() + queue.append((x, y)) + + while queue: + x, y = queue.popleft() + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + + if nx < 0 or ny < 0 or nx >= N or ny >= M: + continue + + if graph[nx][ny] == 0: + continue + + if graph[nx][ny] == 1: + graph[nx][ny] = graph[x][y] + 1 + queue.append((nx, ny)) + + return graph[N-1][M-1] + +print(bfs(0,0)) \ No newline at end of file diff --git "a/wnsmir/DFS/BFS/\354\235\214\353\243\214\354\210\230\354\226\274\353\240\244\353\250\271\352\270\260.py" "b/wnsmir/DFS/BFS/\354\235\214\353\243\214\354\210\230\354\226\274\353\240\244\353\250\271\352\270\260.py" new file mode 100644 index 0000000..3299248 --- /dev/null +++ "b/wnsmir/DFS/BFS/\354\235\214\353\243\214\354\210\230\354\226\274\353\240\244\353\250\271\352\270\260.py" @@ -0,0 +1,25 @@ +N, M = map(int,input().split()) +graph = [] + +for i in range(N): + graph.append(list(map(int, input().split()))) + +def dfs(x,y): + if x<=-1 or x>=N or y<=-1 or y>=M: + return False + if graph[x][y] == 0: + graph[x][y] = 1 + dfs(x-1,y) + dfs(x,y-1) + dfs(x+1,y) + dfs(x,y+1) + return True + return False + +result = 0 +for i in range(N): + for j in range(M): + if dfs(i,j) == True: + result += 1 + +print(result) \ No newline at end of file