Skip to content
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

13-g0rnn #52

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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;
}
27 changes: 16 additions & 11 deletions g0rnn/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
## โœ๏ธ ๊ธฐ๋ก

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
| :---: | :--------: | :--------: | :---------------------------------------------------------------------------: | :-------------------------------------------------: |
| 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 |
| 13์ฐจ์‹œ | 2025.01.05 | ๋ฐฑํŠธ๋ž˜ํ‚น | [์Šคํƒ€ํŠธ์™€ ๋งํฌ](https://www.acmicpc.net/problem/14889) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/52 |


---
50 changes: 50 additions & 0 deletions g0rnn/backtracking/13-g0rnn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// Created by ๊น€๊ท ํ˜ธ on 2025. 1. 5..
//
#include <iostream>
#include <climits>
#include <vector>
using namespace std;

int n, minDiff = INT_MAX;
int s[25][25];
vector<bool> visited;

void sumPoint() {
int start = 0, link = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (visited[i] && visited[j]) start += s[i][j] + s[j][i];
else if (!visited[i] && !visited[j]) link += s[i][j] + s[j][i];
}
}
minDiff = min(minDiff, abs(start - link));
}

// ์ž„์˜์˜ n/2๊ฐœ๋ฅผ ๋ฝ‘์Œ
void dfs(int cur, int cnt) {
if (cnt == n / 2) {
sumPoint();
return;
}
for (int i = cur; i <= n; i++) {
if (!visited[i]) {
visited[i] = true;
dfs(i + 1, cnt + 1);
visited[i] = false;
}
}
}

int main() {
cin >> n;
for (int y = 1; y <= n; y++) {
for (int x = 1; x <= n; x++) {
cin >> s[y][x];
}
}
visited = vector<bool>(n + 1, false);
dfs(1, 0);
cout << minDiff;
return 0;
}
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;
}
Loading