Skip to content

Commit

Permalink
Merge branch 'main' into 14-kangrae-jo
Browse files Browse the repository at this point in the history
  • Loading branch information
kangrae-jo authored Jan 9, 2025
2 parents e0ea0f2 + b56da47 commit 4d346d6
Show file tree
Hide file tree
Showing 15 changed files with 455 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
.idea/
/.vscode
cmake-build-debug/
CMakeLists.txt
81 changes: 81 additions & 0 deletions g0rnn/DFS,BFS/12-g0rnn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// Created by 김균호 on 2025. 1. 2..
//
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

#define FRIEND 1

int n;
int club[55][55];
vector<int> president;
// 첫번째 인자 기준
//priority_queue<pair<int, int>, vector<pair<int, int> >, greater<> > candidate;

int bfs(int a) {
queue<int> q;
vector<bool> 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;
}
26 changes: 15 additions & 11 deletions g0rnn/README.md
Original file line number Diff line number Diff line change
@@ -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 |


---
38 changes: 38 additions & 0 deletions g0rnn/dp/11-g0rnn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Created by 김균호 on 2024. 12. 31..
//
// 1. 조절한 볼륨이 0보다 작거나 max보다 크면 연주할 수 없다 -> -1
// 2. 범위 내의 최댓값을 구하라

#include <iostream>
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;
}
38 changes: 38 additions & 0 deletions g0rnn/graph/10-g0rnn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Created by 김균호 on 2024. 12. 20..
//
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;

const int SANG = 1;
int n, m;
int ret = 0;
vector<unordered_set<int> > relationship;
unordered_set<int> members = {1};

int main() {
cin >> n >> m;
relationship = vector<unordered_set<int> >(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;
}
47 changes: 47 additions & 0 deletions kangrae-jo/Graph/13-kangrae-jo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <iostream>
#include <list>
#include <vector>

using namespace std;

int N, M;
vector<bool> visited;
vector<list<int>> graph;

void dfs(int v, list<int>& r) {
visited[v] = true;
for (int x : graph[v]) {
if (visited[x] == false) dfs(x, r);
}
r.push_front(v);
}

list<int> topologicalSort() {
list<int> r;
for (int v = 1; v <= N; v++) {
if (visited[v] == false) dfs(v, r);
}

return r;
}

int main() {
cin >> N >> M;

visited = vector<bool>(N + 1, false);
graph = vector<list<int>>(N + 1);

while (M--) {
int a, b;
cin >> a >> b;

graph[a].push_back(b);
}

list<int> r = topologicalSort();
for (int i : r) {
cout << i << " ";
}

return 0;
}
28 changes: 28 additions & 0 deletions kangrae-jo/Greedy/11-kangrae-jo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
int N;
cin >> N;

vector<int> 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;
}
37 changes: 37 additions & 0 deletions kangrae-jo/HEAP/12-kangrae-jo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>
#include <queue>

using namespace std;

priority_queue<int> 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;
}
9 changes: 6 additions & 3 deletions kangrae-jo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)|

---
---
3 changes: 3 additions & 0 deletions kokeunho/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
---
34 changes: 34 additions & 0 deletions kokeunho/그리디 알고리즘/11-kokeunho.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit 4d346d6

Please sign in to comment.