-
Notifications
You must be signed in to change notification settings - Fork 37
[최단 경로] 2176283 이윤진 #355
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
Open
yunjin-21
wants to merge
3
commits into
Altu-Bitu-Official:2176283-이윤진2
Choose a base branch
from
yunjin-21:13_assignment
base: 2176283-이윤진2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[최단 경로] 2176283 이윤진 #355
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| { | ||
| "files.associations": { | ||
| "vector": "cpp" | ||
| } | ||
| } |
This file contains hidden or 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,75 @@ | ||
| #include <iostream> | ||
| #include <vector> | ||
| #include <queue> | ||
|
|
||
| using namespace std; | ||
|
|
||
| const int INF = 987654321; | ||
|
|
||
| vector<int> dijkstra(int start, int N, const vector<vector<pair<int, int>>>& graph) | ||
| { | ||
| vector<int> distance(N + 1, INF); | ||
| distance[start] = 0; | ||
|
|
||
| priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; | ||
| pq.push({0, start}); | ||
|
|
||
| while (!pq.empty()) | ||
| { | ||
| int dist = pq.top().first; | ||
| int cur = pq.top().second; | ||
| pq.pop(); | ||
|
|
||
| if (dist > distance[cur]) | ||
| continue; | ||
|
|
||
| for (int i = 0; i < graph[cur].size(); i++) | ||
| { | ||
| int next = graph[cur][i].first; | ||
| int weight = graph[cur][i].second; | ||
|
|
||
| if (distance[next] > dist + weight) | ||
| { | ||
| distance[next] = dist + weight; | ||
| pq.push({distance[next], next}); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return distance; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| int N, M, X; | ||
| cin >> N >> M >> X; | ||
|
|
||
| vector<vector<pair<int, int>>> graph(N + 1); | ||
|
|
||
| for (int i = 0; i < M; i++) | ||
| { | ||
|
|
||
| int start, end, time; | ||
| cin >> start >> end >> time; | ||
| graph[start].push_back({end, time}); | ||
| } | ||
|
|
||
| vector<int> a = dijkstra(X, N, graph); | ||
|
|
||
| int maxTime = 0; | ||
|
|
||
| for (int i = 1; i <= N; i++) | ||
| { | ||
| if (i == X) | ||
| { | ||
| continue; | ||
| } | ||
| vector<int> b = dijkstra(i, N, graph); | ||
| maxTime = max(maxTime, a[i] + b[X]); | ||
| } | ||
|
|
||
| cout << maxTime; | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or 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,73 @@ | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| using namespace std; | ||
|
|
||
| const int SIZE = 100; | ||
|
|
||
| // 방향: 우(0), 상(1), 좌(2), 하(3) | ||
| int dy[4] = { 0, -1, 0, 1 }; | ||
| int dx[4] = { 1, 0, -1, 0 }; | ||
|
|
||
| // 1x1 정사각형 개수 계산 | ||
| int cntSquares(vector<vector<bool>>& plane) { | ||
| int ans = 0; | ||
| for (int i = 0; i < SIZE; i++) { | ||
| for (int j = 0; j < SIZE; j++) { | ||
| // 현재 위치 (i, j)와 이웃한 네 개의 정사각형이 모두 true일때 정사각형의 개수를 1 증가시킴 | ||
|
|
||
| if (plane[i][j] && plane[i + 1][j] && plane[i][j + 1] && plane[i + 1][j + 1]) { | ||
| ans++; | ||
| } | ||
| } | ||
| } | ||
| return ans; | ||
| } | ||
|
|
||
| // 평면에 드래곤 커브를 표시 | ||
| void drawDragonCurve(vector<vector<bool>>& plane, int x, int y, int d, int g) { | ||
| vector<int> direct; // 방향 저장 | ||
| plane[y][x] = plane[y + dy[d]][x + dx[d]] = true; // 평면에 드래곤 커브 초기 위치를 표시 | ||
| x += dx[d]; | ||
| y += dy[d]; | ||
| direct.push_back(d); | ||
| while (g--) { // 1 ~ g 세대까지 반복 | ||
| int size_d = direct.size(); | ||
| for (int j = size_d - 1; j >= 0; j--) { // 이전 세대의 방향을 역순으로 확인 | ||
| int next_d = (direct[j] + 1) % 4; // 오른쪽으로 90도 회전해서 다음 방향 계산 | ||
| x += dx[next_d]; | ||
| y += dy[next_d]; | ||
| plane[y][x] = true; // 평면에 드래곤 커브를 표시 | ||
| direct.push_back(next_d); // 다음 세대의 방향을 저장 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| * 규칙 | ||
| * 0 세대: 0 | ||
| * 1 세대: 0 1 | ||
| * 2 세대: 0 1 2 1 | ||
| * 3 세대: 0 1 2 1 2 3 2 1 | ||
| * ... | ||
| * N 세대: concat((N-1세대), ((N-1세대 거꾸로) + 1)%4) | ||
| * 평면(좌측 상단이 (0, 0))에 드래곤 커브를 그린 후 정사각형의 개수를 계산 | ||
| * 드래곤 커브는 평면 밖으로 나가지 않음으로 범위를 확인할 필요 없음 | ||
| * 1. 0 세대의 드래곤 커브를 먼저 저장 (초기 조건) | ||
| * 2. 세대를 거듭하면서 드래곤 커브를 그림 (규칙을 파악하는 것이 중요) | ||
| * 3. 드래곤 커브가 그려진 평면 상의 정사각형의 개수 계산 (네 꼭짓점 확인) | ||
| */ | ||
|
|
||
| int main() { | ||
| int n, x, y, d, g; | ||
| vector<vector<bool>> plane(SIZE + 1, vector<bool>(SIZE + 1, false)); // 평면 초기화! | ||
| // 입력 | ||
| cin >> n; | ||
| // 연산 & 출력 | ||
| while (n--) { // n개의 드래곤 커브 그리기 | ||
| cin >> x >> y >> d >> g; | ||
| drawDragonCurve(plane, x, y, d, g); | ||
| } | ||
| cout << cntSquares(plane) << '\n'; // 드래곤 커브가 그려진 평면의 정사각형 개수 출력 | ||
| return 0; | ||
| } |
This file contains hidden or 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,69 @@ | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| using namespace std; | ||
|
|
||
| const int INF = 987654321; | ||
|
|
||
| void floydWarshall(int n, vector<vector<int>> &graph) | ||
| { | ||
| for (int k = 1; k <= n; k++) | ||
| { | ||
| for (int i = 1; i <= n; i++) | ||
| { | ||
| for (int j = 1; j <= n; j++) | ||
| { | ||
| if (graph[i][j] > graph[i][k] + graph[k][j]) | ||
| { | ||
| graph[i][j] = graph[i][k] + graph[k][j]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| int n, m; | ||
| cin >> n >> m; | ||
| int ans = 0; | ||
|
|
||
| vector<vector<int>> graph(n + 1, vector<int>(n + 1, INF)); | ||
|
|
||
| for (int i = 1; i <= n; i++) | ||
| { | ||
| graph[i][i] = 0; | ||
| } | ||
|
|
||
| while(m--) | ||
| { | ||
| int a, b; | ||
| cin >> a >> b; | ||
| graph[a][b] = 1; | ||
| } | ||
|
|
||
| floydWarshall(n, graph); | ||
|
|
||
| for (int i = 1; i <= n; i++) | ||
| { | ||
| bool flag = true; | ||
|
|
||
| for (int j = 1; j <= n; j++) | ||
| { | ||
| if (graph[i][j] == INF && graph[j][i] == INF) | ||
| { | ||
| flag = false; | ||
| break; | ||
| } | ||
| } | ||
| if (flag) | ||
| { | ||
| ans++; | ||
| } | ||
| } | ||
|
|
||
| cout << ans; | ||
|
|
||
| return 0; | ||
| } | ||
| /**/ | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
💯