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

20-miniron-v #74

Merged
merged 3 commits into from
Mar 8, 2024
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
3 changes: 3 additions & 0 deletions miniron-v/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@
| 15μ°¨μ‹œ | 2024.02.15 | DP, 큰 수 μ—°μ‚° | [타일링](https://www.acmicpc.net/problem/1793) | [#56](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/56) |
| 16μ°¨μ‹œ | 2024.02.18 | μˆ˜ν•™ | [ν•©](https://www.acmicpc.net/problem/1081) | [#61](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/61) |
| 17μ°¨μ‹œ | 2024.02.21 | DP | [제곱수의 ν•©](https://www.acmicpc.net/problem/1699) | [#64](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/64) |
| 18μ°¨μ‹œ | 2024.02.24 | 이뢄 탐색 | [K번째 수](https://www.acmicpc.net/problem/1300) | [#66](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/66) |
| 19μ°¨μ‹œ | 2024.02.27 | κ·Έλž˜ν”„, λ‹€μ΅μŠ€νŠΈλΌ | [μ΅œλ‹¨κ²½λ‘œ](https://www.acmicpc.net/problem/1753) | [#70](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/70) |
| 20μ°¨μ‹œ | 2024.03.01 | κ·Έλž˜ν”„, ν”Œλ‘œμ΄λ“œ-μ›Œμ…œ | [λλ‚˜μ§€ μ•ŠλŠ” νŒŒν‹°](https://www.acmicpc.net/problem/11265) | [#74](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/74) |
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <iostream>
#include <vector>
#include <queue>

const int INF = 3000001;

std::vector<int> dijkstra(int start, int n, std::vector<std::vector<std::pair<int, int>>>& graph) {
std::vector<int> min_weight(n + 1, INF);
std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::greater<std::pair<int, int>>> pq;

min_weight[start] = 0;
pq.push({ 0, start });

while (pq.empty() == false) {
int cur_weight = pq.top().first;
int cur_node = pq.top().second;
pq.pop();

for (auto& pair : graph[cur_node]) {
int next_node = pair.first;
int next_weight = cur_weight + pair.second;

if (next_weight < min_weight[next_node]) {
min_weight[next_node] = next_weight;
pq.push({ next_weight, next_node});
}
}
}

return min_weight;
}

int main() {
// μž…λ ₯
int V, E, start;
std::cin >> V >> E >> start;

std::vector<std::vector<std::pair<int, int>>> graph(V + 1);
for (int i = 0; i < E; ++i) {
int u, v, w;
std::cin >> u >> v >> w;

graph[u].push_back({v, w});
}

// 계산
std::vector<int> min_weight = dijkstra(start, V, graph);

// 좜λ ₯
for (int i = 1; i < min_weight.size(); ++i) {
if (min_weight[i] == INF) {
std::cout << "INF\n";
continue;
}

std::cout << min_weight[i] << "\n";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>
#include <vector>

int main() {
int n, m;
std::cin >> n >> m;

std::vector<std::vector<int>> graph(n + 1, std::vector<int>(n + 1));

// INF와 자기 μžμ‹ μ„ 0으둜 μ΄ˆκΈ°ν™”ν•˜λŠ” 과정이 μž…λ ₯에 포함됨.
// 즉, λͺ¨λ“  간선이 μ—°κ²°λ˜μ–΄ 있음.
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
std::cin >> graph[i][j];
}
}

for (int k = 1; k <= n; ++k) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
graph[i][j] = std::min(graph[i][j], graph[i][k] + graph[k][j]);
}
}
}

while (m--) {
int a, b, c;
std::cin >> a >> b >> c;

std::cout << ((graph[a][b] <= c) ? "Enjoy other party\n" : "Stay here\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3쀑쑰건문은 μ–Έμ œ 봐도 κ°„κ²°ν•œ 것 κ°™μ•„μš”! κ·ΈλŸ¬λ‚˜ μ œκ°€ μ“Έ 땐 늘 ν—·κ°ˆλ €μ„œ λͺ» μ“°λŠ” ꡬ문 쀑 ν•˜λ‚˜..πŸ˜…

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ‚Όν•­ μ—°μ‚°μžλŠ”.. 가독성적인 μΈ‘λ©΄μ—μ„œλŠ” μΆ”μ²œν•˜μ§„ μ•ŠμŠ΅λ‹ˆλ‹€!
μ§€κΈˆμ€ μ•Œκ³ λ¦¬μ¦˜ ν‘ΈλŠ” 거라 상관 μ—†μ§€λ§Œ λ‚¨μ—κ²Œ μ½”λ“œ κ³΅μœ ν•˜κ±°λ‚˜ ν• λ•ŒλŠ” μ§€μ–‘ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€ :)

}
}
35 changes: 35 additions & 0 deletions miniron-v/이뢄 탐색/1300-K번째 수.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>

// [n][n] λ°°μ—΄μ—μ„œ upper μ΄ν•˜ 수의 개수λ₯Ό μ„Όλ‹€.
long countNum(long n, long upper) {
long count = 0;

for (long i = 1; i <= n && i <= upper; ++i) {
count += std::min(upper / i, n);
}

return count;
}

int main() {
long n, k;
std::cin >> n >> k;

long low = 0, high = k;
long mid = 0;

while (low + 1 < high) {
mid = (low + high) / 2;
long count = countNum(n, mid);

if (count < k) {
low = mid;
}

else if (count >= k) {
high = mid;
}
}

std::cout << high;
}