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

20-miniron-v #74

merged 3 commits into from
Mar 8, 2024

Conversation

miniron-v
Copy link
Member

@miniron-v miniron-v commented Mar 1, 2024

πŸ”— 문제 링크

https://www.acmicpc.net/problem/11265
11265번: λλ‚˜μ§€ μ•ŠλŠ” νŒŒν‹°
λΆ„λ₯˜: κ·Έλž˜ν”„, ν”Œλ‘œμ΄λ“œ-μ›Œμ…œ

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

40λΆ„

✨ μˆ˜λ„ μ½”λ“œ

The Show Must Go On.

λ…Έλž˜ λ“£κΈ°

이번 PR을 λ§ˆμ§€λ§‰μœΌλ‘œ μ•Œκ³ λ¦¬λ“œλ―Έ 5νŒ€μ€ 끝을 λ§žκ² μ§€λ§Œ, 우리의 코딩은 계속될 κ±°λ‹ˆκΉŒ. 이름이 λ§ˆμŒμ— λ“€μ–΄μ„œ κ³¨λžλ‹€.

이전 PR에 올렸던 λ‹€μ΅μŠ€νŠΈλΌ μ•Œκ³ λ¦¬μ¦˜μ€ ν•œ μ μ—μ„œ λ‹€λ₯Έ λͺ¨λ“  점에 κ°€λŠ” μ΅œλ‹¨ 경둜λ₯Ό κ΅¬ν•˜λŠ” 방법이닀.
ν•˜μ§€λ§Œ 이번 λ¬Έμ œλŠ” λͺ¨λ“  μ μ—μ„œ λͺ¨λ“  점으둜 κ°€λŠ” μ΅œλ‹¨ κ²½λ‘œλ“€μ΄ ν•„μš”ν•˜λ‹€. μ΄λŠ” λ‹€μ΅μŠ€νŠΈλΌλ₯Ό 500번 λŒλ €μ„œ ν•΄κ²°ν•  μˆ˜λ„ μžˆμ§€λ§Œ, 이에 νŠΉν™”λœ ν”Œλ‘œμ΄λ“œ-μ›Œμ…œ μ•Œκ³ λ¦¬μ¦˜μ„ μ‚¬μš©ν•˜λ©΄ νŽΈλ¦¬ν•΄μ§„λ‹€.

https://velog.io/@kimdukbae/ν”Œλ‘œμ΄λ“œ-μ›Œμ…œ-μ•Œκ³ λ¦¬μ¦˜-Floyd-Warshall-Algorithm
μœ„ λΈ”λ‘œκ·Έλ₯Ό μ°Έκ³ ν–ˆλ‹€.

ν”Œλ‘œμ΄λ“œ-μ›Œμ…œ μ•Œκ³ λ¦¬μ¦˜

ν”Œλ‘œμ΄λ“œ-μ›Œμ…œ μ•Œκ³ λ¦¬μ¦˜μ€ DPλ₯Ό 기반으둜 ν•œλ‹€.
λ™μž‘κ³Ό κ΅¬ν˜„ 방식이 맀우 κ°„λ‹¨ν•œλ°, 이λ₯Ό ν…Œλ©΄ μ•„λž˜ 두 μ€„λ‘œ λ™μž‘μ„ μš”μ•½ν•  수 μžˆλ‹€.

1. 2차원 배열에 λ°”λ‘œ κ°€λŠ” 거리λ₯Ό μ €μž₯ν•œλ‹€. 
1-1. graph[i][j]라면, iμ—μ„œ j둜 κ°€λŠ” 거리닀.
2. λͺ¨λ“  λ…Έλ“œλ₯Ό μˆœνšŒν•˜λ©°, ν•΄λ‹Ή λ…Έλ“œλ₯Ό κ±°μ³κ°€λŠ” 경우λ₯Ό κ°±μ‹ ν•œλ‹€.
2-1. 1번 λ…Έλ“œμ— λŒ€ν•΄, 2->3 거리λ₯Ό 2->1->3 거리둜 κ°±μ‹ ν•œλ‹€. (더 μž‘μ€ κ²½μš°μ—λ§Œ)

4쀄 같은 2쀄이면 μ„€λͺ…λ˜λŠ” κΉ”λ”ν•œ μ•Œκ³ λ¦¬μ¦˜. 그만큼 κ΅¬ν˜„ μ—­μ‹œ κ°„λ‹¨ν•œλ°

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

3μ€„μ˜ 반볡문과 1μ€„μ˜ DP둜 ν‘œν˜„λœλ‹€.

λ°”λ‘œ 전체 μ½”λ“œλ₯Ό μ‚΄νŽ΄λ³΄μž.

πŸ“š 전체 μ½”λ“œ

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

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

λ‹€μ΅μŠ€νŠΈλΌλ₯Ό λͺ‡ 번 더 ν•΄λ³΄λ €ν–ˆλŠ”λ°, μ–΄λŠμƒˆ 끝이 λ‹€κ°€μ™”λ‹€. λ§ˆμ§€λ§‰μ€ μ˜λ―ΈμžˆλŠ” μ΄λ¦„μœΌλ‘œ ν’€κ³  μ‹Άμ–΄μ„œ, 마침 μ•ˆ ν•΄λ³Έ μœ ν˜•μ˜ λ¬Έμ œμ— 도전해봀닀.

μ•Œκ³ λ¦¬λ“œλ―Έλ₯Ό 톡해 μ‹œκ°„λ³΅μž‘λ„μ— λ¬Έμ œκ°€ μ—†λ‹€λ©΄ λΈŒλ£¨νŠΈν¬μŠ€λΆ€ν„° ν•΄λ³΄λŠ” νƒœλ„, μ›λž˜ μ’‹μ•„ν–ˆλ˜ 그리디와 DP에 λŒ€ν•œ μ˜ˆλ¦¬ν•¨, μ§€κΈˆκ» κΊΌλ €μ™”λ˜ κ·Έλž˜ν”„ λ¬Έμ œλ“€μ— λŒ€ν•œ μžμ‹ κ°μ„ κ°–κ²Œ 됐닀.
λ‹€λ₯Έ μ‚¬λžŒμ˜ μ½”λ“œμ— 리뷰λ₯Ό λ‚¨κΈ°λŠ” 것도, λ‹€λ₯Έ μ‚¬λžŒλ“€μ΄ λ‚΄ μ½”λ“œμ— 리뷰λ₯Ό λ‚¨κ²¨μ£ΌλŠ” 것도 쒋은 κ²½ν—˜μ΄μ—ˆλ‹€. 비둝 μ‹œκ°„ μƒμ˜ μ—¬μœ κ°€ μ—†μ–΄ λ‚˜λŠ” 이번 PR을 끝으둜 μ•Œκ³ λ¦¬λ“œλ―Έλ₯Ό λ– λ‚˜μ§€λ§Œ, μ–Έμ œλ“  λ‹€μ‹œ λŒμ•„μ˜¬ 것이닀.

λ‹€λ“€ μ§€κΈˆκΉŒμ§€ λΆ€μ‘±ν•œ μ„€λͺ… λ“€μ–΄μ£ΌλŠλΌ κ³ μƒν–ˆκ³ , 항상 쒋은 μ½”λ©˜νŠΈλ₯Ό 남겨주어 κ°μ‚¬ν–ˆμŠ΅λ‹ˆλ‹€. 머지 μ•Šμ€ 날에 λ‹€μ‹œ 보길 λ°”λž˜μš”!

Copy link
Member

@bomik0221 bomik0221 left a comment

Choose a reason for hiding this comment

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

2λ‹¬λ™μ•ˆ κ³ μƒν•˜μ…¨μŠ΅λ‹ˆλ‹€! 정말 λ§ˆμ§€λ§‰μ— μ–΄μšΈλ¦¬λŠ” 문제 제λͺ©μ΄λ„€μš”.

사싀 λ‹€λ₯Έ 뢄듀에 λΉ„ν•΄ λ―Όμ² λ‹˜μ˜ μ½”λ“œλŠ” λ³Ό λ•Œ λ§ˆλ‹€ μ½”λ“œμ— λŒ€ν•œ ν”Όλ“œλ°±λ³΄λ‹€λŠ” λ°°μš°λ©΄μ„œ μ«“μ•„κ°€κΈ° λ°”λΉ΄λ˜ 터라, 아쉬움이 쑰금 μžˆλ„€μš”. μ–Έμ  κ°€ λ‹€μ‹œ μŠ€ν„°λ””λ₯Ό μ§„ν–‰ν•˜κ²Œ 되면 κ·Έλ•ŒλŠ” μ§„μ •ν•œ ν”Όλ“œλ°±μ„ ν•  수 있게 λœλ‹€λ©΄ μ’‹κ² λ„€μš”..!! κ·Έλž˜λ„ 덕뢄에 정말 λ§Žμ€ 것을 λ°°μ› λ˜ 것 κ°™μ•„μš”. κ°μ‚¬ν•©λ‹ˆλ‹€!

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.

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

Copy link
Collaborator

@2secondag 2secondag left a comment

Choose a reason for hiding this comment

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

λ…Έλž˜κ°€ κ°μ„±μžˆλ„€μšœ.....
항상 λ―Όμ² λ‹˜ μ½”λ“œλ₯Ό λ³΄λ©΄μ„œ λ°°μ›Œκ°€λŠ”κ²Œ λ§Žμ•˜λŠ”λŽ… μ•„μ‰½λ„€μš”~ λΆ€μ‘±ν•œ 제 μ½”λ“œμ—λ„ μ—΄μ •μ μœΌλ‘œ μ½”λ©˜νŠΈ λ‹¬μ•„μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€~!

Copy link
Collaborator

@Redish03 Redish03 left a comment

Choose a reason for hiding this comment

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

2달간 κ³ μƒν•˜μ…§μ”λ‹ˆλ‹€ :)

항상 리뷰 길게 λ‹¬μ•„μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€ ν—ˆν—ˆ 저도 λ…Έλ ₯은 ν–ˆλŠ”λ° 저도 잘 λͺ¨λ₯΄κ±°λ‚˜ λ‚¨μ—κ²Œ 무슨 말을 ν•΄μ€˜μ•Ό 할지 잘 λͺ¨λ₯΄κ² λ˜ κ²½μš°κ°€ λ§Žλ”λΌκ΅¬μš”,,,γ…Žγ…Ž

ν”Œλ‘œμ΄λ“œ μ›Œμ…œ 해보진 μ•Šμ•˜μ§€λ§Œ...해봐야지 해봐야지 ν•˜λ‹€κ°€ κ²°κ΅­ μ•ˆν•˜κ³  λλƒˆλ„€μš” γ…‹γ…‹γ…‹ γ…  μ΄λ ‡κ²Œλ‚˜λ§ˆ κ°„μ ‘μ²΄ν—˜ 해보고 κ°‘λ‹ˆλ‹€ κ΅Ώ

int a, b, c;
std::cin >> a >> b >> c;

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

Choose a reason for hiding this comment

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

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

@miniron-v miniron-v merged commit 7db163c into main Mar 8, 2024
1 check passed
@miniron-v miniron-v deleted the 20-miniron-v branch March 8, 2024 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants