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

9-mong3125 #34

Merged
merged 2 commits into from
Mar 20, 2024
Merged

9-mong3125 #34

merged 2 commits into from
Mar 20, 2024

Conversation

mong3125
Copy link
Collaborator

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

๋ฏธ๋กœ ํƒ์ƒ‰

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

30๋ถ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

๋ฌธ์ œ ์„ค๋ช…

2์ฐจ์› ๋ฐฐ์—ด์˜ ๋ฏธ๋กœ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฏธ๋กœ๋Š” ๋ฌธ์ž์—ด๋กœ ์ž…๋ ฅ์ด ๋˜๊ณ  1์€ ๊ฐˆ ์ˆ˜ ์žˆ๋Š”๊ณณ 0์€ ๊ฐˆ ์ˆ˜ ์—†๋Š” ๊ณณ์ž…๋‹ˆ๋‹ค.
image
image

์ถœ๋ฐœ์ง€์™€ ๋„์ฐฉ์ง€๋ฅผ ํฌํ•จํ•ด์„œ ๊ฐ€์žฅ ์ ์€ ์ˆ˜์˜ ์นธ์„ ์ด๋™ํ•˜๋Š” ํšŸ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.

์ฝ”๋“œ ์„ค๋ช…

// ์ž…๋ ฅ ๋ฐ›๊ธฐ
๋ฏธ๋กœ๋ฅผ ์ด์ฐจ์› boolean ๋ฐฐ์—ด๋กœ ์ดˆ๊ธฐํ™”
๋ฐฉ๋ฌธ ์—ฌ๋ถ€๋„ ์ด์ฐจ์› boolean ๋ฐฐ์—ด๋กœ ์ดˆ๊ธฐํ™”
string์œผ๋กœ ์ž…๋ ฅ๋ฐ›์€ ๋ฏธ๋กœ๋ฅผ ๋ฐฐ์—ด์— ์ž…๋ ฅ

// ๋ฌธ์ œ ํ•ด๊ฒฐ
BFS ๋ฐฉ์‹์œผ๋กœ ํ˜„์žฌ ๋‹จ๊ณ„์—์„œ ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ๋…ธ๋“œ๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” ๊ณณ(๋ฏธ๋กœ ๋ฐฐ์—ด์—์„œ true์ธ ๊ณณ)๋“ค์„ ์ด๋™ํ•ด๋ด…๋‹ˆ๋‹ค.
(๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ๋…ธ๋“œ๋กœ ์ด๋™ํ•˜๋Š” ์ด์œ ๋Š” ์ด์ „ ๋‹จ๊ณ„์—์„œ ๋” ์งง์€ ๊ฑฐ๋ฆฌ๋กœ ๋‹ฟ์€ ๊ณณ์ด๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.)
๋„์ฐฉ์ง€์— ๋„์ฐฉ์„ ํ•˜๊ฒŒ ๋˜์—ˆ์„๋•Œ ๋ช‡ ๋‹จ๊ณ„์ธ์ง€ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค

// ์ถœ๋ ฅ
๋‹ต์„ ๋ฐ›์•„์„œ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

BFS๋กœ ๋‹จ๊ณ„๋ณ„๋กœ ์ด๋™ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. 2์นธ์„ ์ด๋™ํ–ˆ์„๋•Œ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“  ์žฅ์†Œ์— ๊ฐ€๊ณ , 3์นธ์„ ์ด๋™ํ–ˆ์„๋•Œ, 4์นธ, 5์นธ, ... ์ด๋™ํ•ด์„œ ๋„์ฐฉ์ง€์— ๋„์ฐฉํ•ด์„œ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

์ด ๋ฐฉ๋ฒ•์ด ๊ฐ€๋Šฅํ•œ ์ด์œ ๋Š” ๋ฏธ๋กœ๊ฐ€ ์ตœ๋Œ€ 100 x 100์ด๊ธฐ๋•Œ๋ฌธ์— ๊ฐ€๋Šฅํ•˜๊ณ  ๋งŒ์•ฝ ํฌ๊ธฐ๊ฐ€ ์ปค์ง„๋‹ค๋ฉด ๋‹ค์‹œ ๊ณ ๋ คํ•ด๋ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

  • ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ ๋œ๊ฑด ์•„๋‹ˆ๊ณ  BFS์—์„œ ๋ฒ”์œ„ ๋ฐ–์„ ๋‚˜๊ฐˆ๋•Œ๊ฐ€ ๋งŽ์œผ๋‹ˆ ๋ฒ”์œ„ ์ฒดํฌํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋‘˜๋Ÿฌ ์‹ธ์ค˜์•ผ ํ•œ๋‹ค๋Š”๊ฑธ ์žŠ๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.
    image
    ์ด๋Ÿฐ ์‹์œผ๋กœ์š”.

  • ์ฒ˜์Œ์—” DFS๋ฐฉ์‹์œผ๋กœ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๊ณณ๊นŒ์ง€ ๊ฐ€๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ๊ตฌํ˜„ํ•ด๋ณด๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ ๊ฒฝ์šฐ์˜ ์ˆ˜๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์•„์ ธ์„œ ๋ณ„๋กœ๋„ค์š”. BFS ๋ฌธ์ œ์™€ DFS ๋ฌธ์ œ๋ฅผ ๊ตฌ๋ณ„ํ•˜๋Š” ๋Šฅ๋ ฅ์„ ์ข€ ๋” ๊ธธ๋Ÿฌ์•ผ ๋ ๊ฒƒ ๊ฐ™์•„์š”.

Copy link
Member

@kjs254 kjs254 left a comment

Choose a reason for hiding this comment

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

์ €๋ฒˆ์— ํ‘ธ์…จ๋˜ BFS ๋ฌธ์ œ์˜ ํ™œ์šฉ ๋ฌธ์ œ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

ํƒ์ƒ‰์ด ๋ชฉ์ ์ด ์•„๋‹ˆ๋ผ ์ตœ๋‹จ๊ฑฐ๋ฆฌ ํƒˆ์ถœ์ด ๋ชฉ์ ์ด๊ธฐ์— DFS๊ฐ€ ์•„๋‹Œ BFS๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

DFS๋Š” ๋ณด๋ฌผ์ฐพ๊ธฐ ๋งˆ๋ƒฅ ๋ฏธ๋กœ์˜ ๋ชจ๋“  ๊ณณ์„ ์™„์ „ ํƒ์ƒ‰ํ•  ๋•Œ ์“ฐ์ด๊ณ  BFS๋Š” ๋ฐฉํƒˆ์ถœ ๋งˆ๋ƒฅ ์ตœ๋‹จ์‹œ๊ฐ„ ํƒˆ์ถœ์„ ๋ชฉ์ ์œผ๋กœ ๋‘”๋‹ค๊ณ  ์ƒ๊ฐํ•˜์‹œ๋ฉด ์ž˜ ๊ตฌ๋ถ„ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค ใ…Žใ…Ž

Comment on lines +53 to +54
if (now[0] == n - 1 && now[1] == m - 1) {
return now[2];
Copy link
Member

Choose a reason for hiding this comment

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

now[0]๊ณผ now[1]์˜ ์œ„์น˜๊ฐ€ (N,M) ์ผ ๋•Œ ์ด๋™ ํšŸ์ˆ˜ now[2] ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค๊ณ  ํ•ด์„๋˜๋„ค์š”.

Copy link
Collaborator

@YIM2UL2ET YIM2UL2ET left a comment

Choose a reason for hiding this comment

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

๋…ธ๋“œ๋ฅผ ๋๊นŒ์ง€ ํƒ์ƒ‰ํ•˜๋Š” ๋ฌธ์ œ๋Š” DFS๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , ๋๊นŒ์ง€ ํƒ์ƒ‰ํ•˜์ง€ ์•Š๊ณ  ์ตœ๋Œ€ํ•œ ๋…ธ๋“œ๋ฅผ ๊นŠ๊ฒŒ ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š๋„๋ก ํ•˜๋Š” ๋ฌธ์ œ๋Š” BFS๋ฅผ ์‚ฌ์šฉํ•ด์•ผ๊ฒ ๋„ค์š”. ๊ตํ›ˆ ํ•˜๋‚˜ ์–ป๊ณ  ๊ฐ‘๋‹ˆ๋‹ค. ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!

Copy link
Collaborator

@rivkms rivkms left a comment

Choose a reason for hiding this comment

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

์ฒ˜์Œ์— ์™œ BFS๋ฅผ ์จ์•ผํ•˜๋Š”์ง€์— ๋Œ€ํ•ด ๋˜๊ฒŒ ๋งŽ์ด ๊ณ ๋ฏผํ–ˆ์—ˆ๋Š”๋ฐ ๋‹ค๋ฅธ๋ถ„๋“ค์ด ์„ค๋ช…ํ•ด์ฃผ์‹  ๊ฒƒ์„ ํ†ตํ•ด ์ดํ•ดํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.
๊ฐœ์ธ์ ์œผ๋กœ ๋‹ค๋ฅธ ๋ฌธ์ œ๋“ค์„ ํ’€ ๋•Œ BFS, DFS์— ๋Œ€ํ•œ ์ดํ•ด๊ฐ€ ์•„์ง ๋ถ€์กฑํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋Š”๋ฐ ์ €๋„ ์กฐ๊ธˆ ๋” ๊ณต๋ถ€ํ•ด๋ณด์•„์•ผ ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค ๐Ÿ˜

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