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

14-kokeunho #55

Open
wants to merge 1 commit into
base: 13-kokeunho
Choose a base branch
from
Open

14-kokeunho #55

wants to merge 1 commit into from

Conversation

kokeunho
Copy link
Collaborator

@kokeunho kokeunho commented Jan 8, 2025

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

[BOJ] ๋ฏธ๋กœ๋งŒ๋“ค๊ธฐ https://www.acmicpc.net/problem/2665

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

1h

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

์ค€์šฉ๋‹˜์˜ 12์ฐจ์‹œ PR์„ ํ’€์–ด๋ณด๊ณ  ์žฌ๋ฏธ์žˆ์–ด์„œ ๋น„์Šทํ•œ ๋ฌธ์ œ๋ฅผ ํ’€์–ด๋ณด๋ ค ํ–ˆ์Šต๋‹ˆ๋‹ค.
ํ˜ธ๊ธฐ๋กญ๊ฒŒ ๋„์ „ํ–ˆ์ง€๋งŒ ํ’€์ด๋ฅผ ์ข€ ๋ดค์Šต๋‹ˆ๋‹ค...

ํ•ด๋‹น ๋ฌธ์ œ์—์„œ๋Š” ์šฐ์„ ์ˆœ์œ„ ํ๋ฅผ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

์šฐ์„ ์ˆœ์œ„ ํ pq์—๋Š” x, y, brokenwall(x,y ์ง€์ ๊นŒ์ง€ ๋ถ€์ˆœ ๋ฒฝ์˜ ์ˆ˜)๋ฅผ ๋„ฃ์Šต๋‹ˆ๋‹ค.
์ƒํ•˜์ขŒ์šฐ๋กœ ์›€์ง์ด๋ฉฐ ๋„์ฐฉํ•œ ์ง€์ ์ด ๊ฒ€์€์ƒ‰์ด๋ผ๋ฉด brokenwall์— 1 ์ฆ๊ฐ€ ์‹œํ‚จ ๊ฐ’์„ newBrokenwall(nx, ny ์ง€์ ๊นŒ์ง€ ๋ถ€์ˆœ ๋ฒฝ์˜ ์ˆ˜)๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  newBrokenwall๊ณผ ๊ธฐ์กด์˜ nx, ny ์ง€์ ๊นŒ์ง€ ๋ถ€์ˆœ ๋ฒฝ์˜ ์ˆ˜ distance[nx][ny]๋ฅผ ๋น„๊ตํ•˜์—ฌ ๋” ์ž‘์€ ๊ฐ’์„ pq์— ์ขŒํ‘œ์™€ ํ•จ๊ป˜ ๋„ฃ์Šต๋‹ˆ๋‹ค.

if (distance[x][y] < brokenwall) continue;

๋Š” ์ด๋ฏธ ์ตœ์†Œ์˜ ๋ฒฝ์„ ๊นจ๊ณ  ๋„์ฐฉํ•œ ์ ์ด ์žˆ๋‹ค๋ฉด ์ด๋ฒˆ ๊ฒฝ๋กœ๋Š” ๋ฌด์‹œํ•œ๋‹ค๋Š” ๋œป์ž…๋‹ˆ๋‹ค.

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

์šฐ์„ ์ˆœ์œ„ ํ ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•ด ์ข€ ๋” ์•Œ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์ž๋ฐ”์—์„œ ์šฐ์„ ์ˆœ์œ„ ํ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์ตœ์†Œ ํž™(์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ)์œผ๋กœ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค.

ํ•ด๋‹น ๋ฌธ์ œ ํ’€์ด ์ฝ”๋“œ์—์„œ

PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> a[2] - b[2]);

๋Š” ๋žŒ๋‹ค ํ‘œํ˜„์‹์„ ์‚ฌ์šฉํ•˜์—ฌ ์ •๋ ฌ ๊ธฐ์ค€์„ ์ •์˜ํ•œ ๊ฒƒ์œผ๋กœ
a, b ์š”์†Œ๋ฅผ ๋น„๊ตํ•  ๋•Œ brokenwall์ด ์žˆ๋Š” ์œ„์น˜์ธ 2๋ฒˆ ์ธ๋ฑ์Šค์˜ ๊ฐ’์„ ๋บ„์…ˆํ•˜์—ฌ ์–‘์ˆ˜์ด๋ฉด b๊ฐ€, ์Œ์ˆ˜์ด๋ฉด a๊ฐ€ ๋†’์€ ์šฐ์„ ์ˆœ์œ„๋ฅผ ๊ฐ–์Šต๋‹ˆ๋‹ค.

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.

1 participant