user-img
์šฐ์„ ์ˆœ์œ„ํ ์ด์šฉ ๋‹ค์ต์ŠคํŠธ๋ผ 1
thumbnail
๋‹ค์ต์ŠคํŠธ๋ผ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ตฌํ˜„๋ฐฉ๋ฒ• (Java)
4. ๊ตฌํ˜„(1) ์ˆœ์ฐจ ํƒ์ƒ‰์ €๋ฒˆ ๊ฒŒ์‹œ๊ธ€์—์„œ ์„ค๋ช…ํ•œ ์ž‘๋™์›๋ฆฌ ๊ทธ๋Œ€๋กœ ๊ตฌํ˜„ํ•œ ๋ฐฉ์‹์ด๋‹ค.๋ฐฉ๋ฌธํ•œ ์ •์ ๊ณผ ๊ทธ๋ ‡์ง€ ์•Š์€ ์ •์  ๊ตฌ๋ถ„์„ ์œ„ํ•ด์„œ, ๋ฐฉ๋ฌธ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•œ๋‹ค.ํ˜„์žฌ ์ •์ ์—์„œ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๊ฐ„์„ ์„ ํ†ตํ•ด dist[] ๋ฐฐ์—ด์„ ์ตœ์‹ ํ™”ํ•˜๊ณ , ๋ฐฉ๋ฌธ ๋ฐฐ์—ด์„ ํ†ตํ•ด, ํ˜„์žฌ๊นŒ์ง€ ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ์ •์  ์ค‘ ์‹œ์ž‘ ์ •์ ์—์„œ ์ตœ๋‹จ ๊ฑฐ๋ฆฌ๋กœ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ์ •์ ์„ ํƒํ•ด์•ผ ํ•œ๋‹ค.์—ฌ๊ธฐ์„œ ์ตœ์•…์˜ ๊ฒฝ์šฐ, ์ •์ ์˜ ์ˆ˜๊ฐ€ N๊ฐœ๋ผ๋ฉด, ๋งค๋ฒˆ N๋ฒˆ์˜ ์ •์ ์„ ํƒ์ƒ‰ํ•ด ๋‹ค์Œ ๋ฐฉ๋ฌธํ•ด์•ผํ•  ์ •์ ์„ ์ฐพ์•„์•ผ ํ•˜๊ณ , ์ด ํ–‰์œ„๋ฅผ ๋ชจ๋“  ์ •์ ์„ ๋ฐฉ๋ฌธํ•  ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณตํ•ด์•ผ ํ•˜๋ฏ€๋กœ ์ตœ์•…์˜ ์‹œ๊ฐ„๋ณต์žก๋„๋Š” O(N^2)์ด ๋“ ๋‹ค.import java.io.*;import java.util.*;public class ์ˆœ์ฐจํƒ์ƒ‰_๋‹ค์ต์ŠคํŠธ๋ผ { static int [] dist = new int [N]; ..
2024.10.18
์•Œ๊ณ ๋ฆฌ์ฆ˜/์•Œ๊ณ ๋ฆฌ์ฆ˜-์ด๋ก