์ ์ฒด ๊ธ
-
[์ฝ๋ํธ๋ฆฌ ์กฐ๋ณ๊ณผ์ ] Dx, Dy ํ ํฌ๋Algorithm 2024. 8. 18. 23:13
์ฝ๋ฉํ ์คํธ์ ๊ฐ์ด ๋จ์ด์ง๊ธฐ๋ ํ๊ณ , ์ฝํ ๋ฅผ ๊พธ์คํ๊ฒ ๋์ ํ๊ธฐ ์ํด ์ฝ๋ํธ๋ฆฌ ์กฐ๋ณ๊ณผ์ ์ ์ฐธ์ฌํ๊ฒ ๋์๋ค.๋ด๊ฐ ์ค์ค๋ก ๊ณต๋ถํ ๊ฒ์ ์กฐ๋ณ๊ณผ์ ์ ์ฐธ์ฌํ ๊ฒธ, ๊ธฐ๋ก์ ๋จ๊ธฐ๊ธฐ์ํด ์ ๋ฆฌํ๋ ค๊ณ ํ๋ค. dx, dy์ ํ ํฌ๋์ฐ๋ฆฌ๋ ํน์ ๋ฐฉํฅ(๋์๋จ๋ถ)์ ์ด๋ํ๋ ค๊ณ ํ๋ ๊ฒ์ ์ฝ๋๋ก ํํํ ๋, ์๋์ ๊ฐ์ด ์ฝ๋๋ก ๋ฐ๊ฟ๋ณผ ์ ์์ต๋๋ค. 0123dx10-10dy0-101๋ฐฉํฅ ํ์ ์ ์ํ dx, dy ์ ์ ๋ฐฉ๋ฒ์ฐ๋ฆฌ๋ ์๊ณ ๋ฐฉํฅ์ผ๋ก 90๋ ํ์ ์ ํ๋ ๋ฐฉ๋ฒ์ผ๋ก dirNum์ 1์ฉ ์ฆ๊ฐ์ํค๋ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ ์ ์๋ค.์๋๋ ์์ ์ฝ๋์ด๋ค.int[] dx = new int[]{1, 0, -1, 0};int[] dy = new int[]{0, -1, 0, 1};int dirNum = 1;int nx, ny; if (dirNum ==..
-
[์ฝ๋ํธ๋ฆฌ ์กฐ๋ณ๊ณผ์ ] ์๋ฎฌ๋ ์ด์ Algorithm 2024. 8. 11. 21:48
์ฝ๋ฉํ ์คํธ์ ๊ฐ์ด ๋จ์ด์ง๊ธฐ๋ ํ๊ณ , ์ฝํ ๋ฅผ ๊พธ์คํ๊ฒ ๋์ ํ๊ธฐ ์ํด ์ฝ๋ํธ๋ฆฌ ์กฐ๋ณ๊ณผ์ ์ ์ฐธ์ฌํ๊ฒ ๋์๋ค.๋ด๊ฐ ์ค์ค๋ก ๊ณต๋ถํ ๊ฒ์ ์กฐ๋ณ๊ณผ์ ์ ์ฐธ์ฌํ ๊ฒธ, ๊ธฐ๋ก์ ๋จ๊ธฐ๊ธฐ์ํด ์ ๋ฆฌํ๋ ค๊ณ ํ๋ค. ์๋ฎฌ๋ ์ด์ ์๋ฎฌ๋ ์ด์ ์ด๋, BFS๋ ์ฌ๊ท์ ๊ฐ์ด ํน์ ์๋ฃ๊ตฌ์กฐ ๋๋ ์๊ณ ๋ฆฌ์ฆ์ ์ข ์๋์ง ์๊ณ ์ฃผ์ด์ง ๋ฌธ์ ์ํฉ์ ๊ตฌํํ๋ฉด ๋๋๋ฐ ์ด ๋ ๊ตฌํ์ด ๋นก์ธ๊ฒ ํ์ํ ๊ฒ๋ค์ ํฉ์ณ ์๋ฎฌ๋ ์ด์ ์ ํ์ ๋ฌธ์ ๋ผ๊ณ ํ๋ค. ํ๋ฅธ ์๊ฐ ๊ณ์ฐhttps://www.codetree.ai/missions/5/problems/time-to-time?&utm_source=clipboard&utm_medium=text ์ฝ๋ํธ๋ฆฌ | ์ฝ๋ฉํ ์คํธ ์ค๋น๋ฅผ ์ํ ์๊ณ ๋ฆฌ์ฆ ์ ์๊ตญ๊ฐ๋ํ๊ฐ ๋ง๋ ์ฝ๋ฉ ๊ณต๋ถ์ ๊ฐ์ด๋๋ถ ์ฝ๋ฉ ์์ด๋ณด๋ถํฐ ๊ฟ์ ์ง์ฅ ์ฝํ ํฉ๊ฒฉ๊น์ง, ๊ตญ๊ฐ๋ํ..
-
[์ฝ๋ํธ๋ฆฌ ์กฐ๋ณ๊ณผ์ ] ๊ฐ์ฒดAlgorithm 2024. 8. 4. 21:21
์ฝ๋ฉํ ์คํธ์ ๊ฐ์ด ๋จ์ด์ง๊ธฐ๋ ํ๊ณ , ์ฝํ ๋ฅผ ๊พธ์คํ๊ฒ ๋์ ํ๊ธฐ ์ํด ์ฝ๋ํธ๋ฆฌ ์กฐ๋ณ๊ณผ์ ์ ์ฐธ์ฌํ๊ฒ ๋์๋ค.๋ด๊ฐ ์ค์ค๋ก ๊ณต๋ถํ ๊ฒ์ ์กฐ๋ณ๊ณผ์ ์ ์ฐธ์ฌํ ๊ฒธ, ๊ธฐ๋ก์ ๋จ๊ธฐ๊ธฐ์ํด ์ ๋ฆฌํ๋ ค๊ณ ํ๋ค. ๊ฐ์ฒด ์ ๋ ฌํ๊ธฐpublic class Main { public static class Student { String id; int score; public Student(String id, int score) { this.id = id; this.score = score; } } } ์์์ ๊ฐ์ด Student๋ผ๋ ๊ฐ์ฒด๊ฐ ์๊ณ , Score๋ฅผ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ์ ํ๊ธฐ ์ํด์ Comparable ์ธํฐํ์ด์ค๊ฐ ํ์ํ๋ค. Compara..
-
[์ฝ๋ํธ๋ฆฌ ์กฐ๋ณ๊ณผ์ ] ์ฌ๊ทํจ์Algorithm 2024. 7. 28. 17:12
์ฝ๋ฉํ ์คํธ์ ๊ฐ์ด ๋จ์ด์ง๊ธฐ๋ ํ๊ณ , ์ฝํ ๋ฅผ ๊พธ์คํ๊ฒ ๋์ ํ๊ธฐ ์ํด ์ฝ๋ํธ๋ฆฌ ์กฐ๋ณ๊ณผ์ ์ ์ฐธ์ฌํ๊ฒ ๋์๋ค.๋ด๊ฐ ์ค์ค๋ก ๊ณต๋ถํ ๊ฒ์ ์กฐ๋ณ๊ณผ์ ์ ์ฐธ์ฌํ ๊ฒธ, ๊ธฐ๋ก์ ๋จ๊ธฐ๊ธฐ์ํด ์ ๋ฆฌํ๋ ค๊ณ ํ๋ค. ์ฌ๊ทํจ์ํจ์ f๊ฐ ํด๋น ํจ์๋ฅผ ๊ตฌํํ๋ ๋ฐ ๋์ผํ ํจ์ f๋ฅผ ๋ค์ ์ด์ฉํ๊ฒ ๋๋ ๊ฒ์ ์ฌ๊ทํจ์ ๋ผ๊ณ ๋ถ๋ฆ ๋๋ค.์ฌ๊ทํจ์์ ์ค์ํ ์กฐ๊ฑด์ ์ข ๋ฃ์กฐ๊ฑด์ด๋ค. ์ข ๋ฃ ์กฐ๊ฑด์ ์ ์ ํ๊ฒ ์ค์ ํด์ค์ผ๋ง, ์ฌ๊ท ํจ์๋ ์ฌ๋ฐ๋ฅด๊ฒ ๋์ํ๊ฒ ๋๋ค. ๊ฐ์ ๋ฐํํ์ง ์๋ ์ฌ๊ทํจ์๊ฐ์ ๋ฐํํ๋ ์ฌ๊ทํจ์ ์ด๋ ๊ฒ 2๊ฐ์ง๋ก ๋๋ ์ ์๋ค. 1. ๊ฐ์ ๋ฐํํ์ง ์๋ ์ฌ๊ทํจ์ ๊ฐ์ ๋ฐํํ์ง ์๋ ์ฌ๊ทํจ์์ ๋ํ์ ์ธ ๋ฌธ์ ๋ ๋ฐ๋ณต ์ถ๋ ฅํ๊ธฐ ์ด๋ค.https://www.codetree.ai/missions/5/problems/repeated-output-2/in..
-
[Java] 11726 2×n ํ์ผ๋งAlgorithm/๋ฐฑ์ค 2023. 8. 2. 13:46
1. ๋ฌธ์ ๐ https://www.acmicpc.net/problem/11726 11726๋ฒ: 2×n ํ์ผ๋ง 2×n ํฌ๊ธฐ์ ์ง์ฌ๊ฐํ์ 1×2, 2×1 ํ์ผ๋ก ์ฑ์ฐ๋ ๋ฐฉ๋ฒ์ ์๋ฅผ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ์๋ ๊ทธ๋ฆผ์ 2×5 ํฌ๊ธฐ์ ์ง์ฌ๊ฐํ์ ์ฑ์ด ํ ๊ฐ์ง ๋ฐฉ๋ฒ์ ์์ด๋ค. www.acmicpc.net 2. ์ ์ถ๋ ฅ ์ ๐ ใ ใดใ ใ ใดใ 3. ์๊ณ ๋ฆฌ์ฆ โ 1. ๊ฐ์ง๋ฌธ์ ์ ์ dp[n] := 2*n ํ์ผ์ ํ ์ ์๋ ๊ฒฝ์ฐ์ ์ 2. ๊ฐ์ฅ ์์ ๋ฌธ์ ํด๊ฒฐํ๊ธฐ 3. ์ ํ์ ์ธ์ฐ๊ธฐ dp[n] = dp[n - 1] + dp[n - 2] 4. ์์ค์ฝ๋ ๐ป import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReade..
-
[Java] H-indexAlgorithm/ํ๋ก๊ทธ๋๋จธ์ค 2023. 4. 11. 11:38
1. ๋ฌธ์ ๐ https://school.programmers.co.kr/learn/courses/30/lessons/42747 ํ๋ก๊ทธ๋๋จธ์ค ์ฝ๋ ์ค์ฌ์ ๊ฐ๋ฐ์ ์ฑ์ฉ. ์คํ ๊ธฐ๋ฐ์ ํฌ์ง์ ๋งค์นญ. ํ๋ก๊ทธ๋๋จธ์ค์ ๊ฐ๋ฐ์ ๋ง์ถคํ ํ๋กํ์ ๋ฑ๋กํ๊ณ , ๋์ ๊ธฐ์ ๊ถํฉ์ด ์ ๋ง๋ ๊ธฐ์ ๋ค์ ๋งค์นญ ๋ฐ์ผ์ธ์. programmers.co.kr 2. ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ 1. ์ ๋ ฌํด์ ๊ฐ์ฅ ํฐ ์ซ์ ๊ตฌํ๊ธฐ 2. ์ธ์ฉ๋ ๋ ผ๋ฌธ์ ๊ฐ์์ ์ธ์ฉ๋์ง ์์ ๋ ผ๋ฌธ ๊ฐ์ ์ธ๊ธฐ 3. h๋ฒ ์ด์ ์ธ์ฉ๋ ๋ ผ๋ฌธ์ด hํธ ์ด์์ด๊ณ ๋๋จธ์ง ๋ ผ๋ฌธ์ด h๋ฒ ์ดํ ์ธ์ฉ๋์๋ค๋ฉด h์ ์ต๋๊ฐ์ ๊ตฌํ๊ธฐ 4. ์์ค์ฝ๋ ๐ป import java.util.*; class Solution { public int solution(int[] citations) ..
-
[Java] ์นดํซAlgorithm/ํ๋ก๊ทธ๋๋จธ์ค 2023. 4. 4. 11:24
1. ๋ฌธ์ ๐ https://school.programmers.co.kr/learn/courses/30/lessons/42842 2. ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ ๋ ธ๋์์ ๊ฐ์์ ๋ฐ๋ผ์ ๊ฐ์์ ๊ฐ์๊ฐ ๋ฌ๋ผ์ง๊ธฐ๋๋ฌธ์ ๋ ธ๋์์ ๊ฐ์๊ฐ ์ฐ์ ์ด๋ผ๊ณ ์๊ฐํ๋ค! ์กฐ๊ฑด์์ ๊ฐ๋ก์ ๊ฐ์๊ฐ ๋ ๊ธธ๋ค๊ณ ๋์์์์ผ๋ฏ๋ก ์กฐ๊ฑด์ ์ ๋ฃ์ด์ ๋ ธ๋์์ ๊ฒฉ์๋ฅผ ๊ตฌํด์คฌ๋ค. 1. ๋ ธ๋์ ๊ฐ๋ก ์ธ๋ก ๊ตฌํ๊ธฐ 2. ๊ฐ์ ๊ฐ๋ก ์ธ๋ก๋ ๊ฐ๊ฐ ๋ ธ๋์๊ฐ๋ก + 2 ๋ ธ๋์์ธ๋ก +2 ์ด๋ค. 3. ๊ฐ์ ๊ฐ๋ก * ๊ฐ์ ์ธ๋ก๊ฐ ํ๋ผ๋ฏธํฐ๋ก ์ฃผ์ด์ง ๋ ธ๋์ + ๊ฐ์ ๊ณผ ๊ฐ์์ง ์ฒดํฌ (์ค์) 4. ์์ค์ฝ๋ ๐ป import java.util.*; class Solution { static int width, height; public int[] solution(in..
-
[Python] 11501 ์ฃผ์Algorithm/๋ฐฑ์ค 2023. 2. 16. 17:37
1. ๋ฌธ์ ๐ https://www.acmicpc.net/problem/11501 11501๋ฒ: ์ฃผ์ ์ ๋ ฅ์ ์ฒซ ์ค์๋ ํ ์คํธ์ผ์ด์ค ์๋ฅผ ๋ํ๋ด๋ ์์ฐ์ T๊ฐ ์ฃผ์ด์ง๋ค. ๊ฐ ํ ์คํธ์ผ์ด์ค ๋ณ๋ก ์ฒซ ์ค์๋ ๋ ์ ์๋ฅผ ๋ํ๋ด๋ ์์ฐ์ N(2 ≤ N ≤ 1,000,000)์ด ์ฃผ์ด์ง๊ณ , ๋์งธ ์ค์๋ ๋ ๋ณ ์ฃผ๊ฐ๋ฅผ ๋ํ www.acmicpc.net 2. ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ ์ ๋ ฅ๊ฐ์ด ํฐ ๊ฒ์ ๋ณด๊ณ ๊ทธ๋ฆฌ๋์ธ๊ฐ dp์ธ๊ฐ ์๊ฐํด๋ณด๋ค๊ฐ ์ ์ผ ํฐ ๊ฐ์ ํ๋ฉด ์ต๋ ์ด์ต์ด ๋์ค๋ฏ๋ก -> ๊ทธ๋ฆฌ๋ ๋ผ๊ณ ์๊ฐํ์๋ค ์ฒ์์ ์์์๋ถํฐ ์ฐจ๊ทผ์ฐจ๊ทผ ์ํํด๊ฐ๋ฉด์ ํ๋ ๋ก์ง์ผ๋ก ์งฐ์ง๋ง 80ํผ์ฏค์์ ์๊ฐ์ด๊ณผ๊ฐ ๋ฌ๋ค. ์์์ ์ํํ๊ฒ ๋๋ฉด ๋ฆฌ์คํธ๋ฅผ ์๋ผ์ฃผ๋ ์์ ์ ๊ณ์ํด์ฃผ์ด์ผํ๋ค. ์๋๋ฉด 7, 6, 9, 1, 6 ์ด๋ผ๋ฉด 7, 6 ์ 9..