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

19-miniron-v #70

Merged
merged 2 commits into from
Mar 6, 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
2 changes: 2 additions & 0 deletions miniron-v/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@
| 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) |
---
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;

Choose a reason for hiding this comment

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

std::greater<>

pair<int, int> ํƒ€์ž…์ด ์ถ”๋ก ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๊ตณ์ด pair<int, int>๋ฅผ ์ ์–ด์ฃผ์ง€ ์•Š์•„๋„ ๋œ๋‹ต๋‹ˆ๋‹น

Copy link
Collaborator

Choose a reason for hiding this comment

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

๊ทธ๋Ÿผ์š”~

Copy link
Member Author

Choose a reason for hiding this comment

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

์œ ๋‹ˆํ‹ฐ๋„ new Vector3()๋กœ ์ ๋˜ ๊ฑฐ new()๋กœ ์ƒ์„ฑ๋˜๊ฒŒ ํ•ด๋†จ๋˜๋ฐ... ์ ์  ์ฝ”๋“œ๊ฐ€ ์งง์•„์ง€๋Š” ์ชฝ์œผ๋กœ ๋ฐœ์ „ํ•˜๋„ค์š”.


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

Choose a reason for hiding this comment

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

์ œ PR์—์„œ ๊ตํ™ฉ์ฟค์ด ์–˜๊ธฐํ•ด์คฌ๋˜ ๊ฑฐ ๊ฐ™์€๋ฐ make_pair()์ด๋‚˜ ๋ฉ”์„œ๋“œ ๋ณด๋‹ค {x, y}๋กœ ๋„ฃ๋Š”๊ฑธ ์ถ”์ฒœ๋“œ๋ฆฌ๋”๋ผ๊ตฌ์š” :)

Copy link
Member Author

Choose a reason for hiding this comment

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

๋„ˆ๋ฌด ํŽธํ•˜๋”๋ผ๊ณ ์š”... std::make_pair(x, y)๋ฅผ ์•ˆ ์จ๋„ ๋„๋”˜๋‹ค๋‹ˆ


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

Choose a reason for hiding this comment

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

if(min_weight[cur_node] < cur_weight) {
    continue;
}

๋ณดํ†ต ์—ฌ๊ธฐ์— ์ด๋Ÿฐ ์‹์œผ๋กœ ์ธ์ ‘ ๋…ธ๋“œ์— ๋Œ€ํ•ด ๊ฒ€์‚ฌํ•  ํ•„์š”๋„ ์—†๋Š” ๊ฒฝ์šฐ๋ฅผ ๊ฑธ๋Ÿฌ์ฃผ๋Š” ์ผ€์ด์Šค๋ฅผ ๋„ฃ์–ด์ฃผ๊ธฐ๋„ ํ•˜๋”๋ผ๊ตฌ์š”. ์ผ๋ถ€ ๋ฌธ์ œ๋Š” ์ด ์กฐ๊ฑด๋ฌธ์ด ์—†์œผ๋ฉด ํ„ฐ์ง€๋”๋ผ๊ตฌ์š”...

Copy link
Member Author

Choose a reason for hiding this comment

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

์•„๋งˆ ์ฝ”๋”ฉ ์Šคํƒ€์ผ์˜ ์ฐจ์ด์ธ ๊ฒƒ ๊ฐ™์ง€๋งŒ,

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});
	}
}

์ด ๊ตฌ๋ฌธ์—์„œ ๊ฒ€์‚ฌํ•  ํ•„์š”๊ฐ€ ์—†๋Š” ๋…ธ๋“œ๋Š” ํ์— push ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ„ฐ์ง€์ง€ ์•Š๋Š” ์ด์œ !

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,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;
}