-
Notifications
You must be signed in to change notification settings - Fork 0
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
19-miniron-v #70
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ PR์์ ๊ตํฉ์ฟค์ด ์๊ธฐํด์คฌ๋ ๊ฑฐ ๊ฐ์๋ฐ There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if(min_weight[cur_node] < cur_weight) {
continue;
} ๋ณดํต ์ฌ๊ธฐ์ ์ด๋ฐ ์์ผ๋ก ์ธ์ ๋ ธ๋์ ๋ํด ๊ฒ์ฌํ ํ์๋ ์๋ ๊ฒฝ์ฐ๋ฅผ ๊ฑธ๋ฌ์ฃผ๋ ์ผ์ด์ค๋ฅผ ๋ฃ์ด์ฃผ๊ธฐ๋ ํ๋๋ผ๊ตฌ์. ์ผ๋ถ ๋ฌธ์ ๋ ์ด ์กฐ๊ฑด๋ฌธ์ด ์์ผ๋ฉด ํฐ์ง๋๋ผ๊ตฌ์... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pair<int, int> ํ์ ์ด ์ถ๋ก ๋๊ธฐ ๋๋ฌธ์ ๊ตณ์ด pair<int, int>๋ฅผ ์ ์ด์ฃผ์ง ์์๋ ๋๋ต๋๋น
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ทธ๋ผ์~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ๋ํฐ๋ new Vector3()๋ก ์ ๋ ๊ฑฐ new()๋ก ์์ฑ๋๊ฒ ํด๋จ๋๋ฐ... ์ ์ ์ฝ๋๊ฐ ์งง์์ง๋ ์ชฝ์ผ๋ก ๋ฐ์ ํ๋ค์.