-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 14-kangrae-jo
- Loading branch information
Showing
15 changed files
with
455 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.DS_Store | ||
.idea/ | ||
/.vscode | ||
cmake-build-debug/ | ||
CMakeLists.txt |
This file contains 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
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; | ||
} |
This file contains 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
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 | | ||
|
||
|
||
--- |
This file contains 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
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; | ||
} |
This file contains 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
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; | ||
} |
This file contains 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
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; | ||
} |
This file contains 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
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; | ||
} |
This file contains 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
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; | ||
} |
This file contains 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
This file contains 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
This file contains 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
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); | ||
} | ||
} |
Oops, something went wrong.