Skip to content

Commit

Permalink
Merge branch 'main' into 17-H0ngJu
Browse files Browse the repository at this point in the history
  • Loading branch information
H0ngJu authored May 25, 2024
2 parents 43ee014 + 93acc1f commit dd3422e
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
49 changes: 49 additions & 0 deletions H0ngJu/BFS/λ±€κ³Ό 사닀리 κ²Œμž„.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import sys
from collections import deque

def input(): return sys.stdin.readline().rstrip()

N, M = map(int, input().split())
ladder = [list(map(int, input().split())) for _ in range(N)]
snake = [list(map(int, input().split())) for _ in range(M)]
game = [i for i in range(1,101)]
visited = [0 for _ in range(100)]
q = deque()

q.append((1,0))
visited[0] = 1

while q:
cur, dice = q.popleft()
if cur == 100:
print(dice)
break
for i in range(1, 7):
check = 0

if cur + i > 100: continue

# 사닀리 갈 수 μžˆλŠ”μ§€ 검사
for l, n in ladder:
if cur + i == l:
if visited[n-1] == 0:
q.append((n, dice+1))
visited[n-1] = 1
check = 1
break

if check: continue
# λ±€ μžˆλŠ”μ§€ 검사
for s, n in snake:
if cur + i == s:
if visited[n-1] == 0:
q.append((n, dice+1))
visited[n-1] = 1
check = 1
break

if check: continue
# κ·Έ μ™Έ
if visited[cur + i-1] == 0:
q.append((cur + i, dice + 1))
visited[cur + i-1] = 1
1 change: 1 addition & 0 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
| 13μ°¨μ‹œ | 2024.05.06 | 완전탐색 | [리λͺ¨μ»¨](https://www.acmicpc.net/problem/1107) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/181 |
| 14μ°¨μ‹œ | 2024.05.09 | DFS | [μΉ˜ν‚¨λ°°λ‹¬](https://www.acmicpc.net/problem/15686) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/183 |
| 15μ°¨μ‹œ | 2024.05.14 | 그리디 | [A와 B](https://www.acmicpc.net/problem/12904) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/188 |
| 16μ°¨μ‹œ | 2024.05.14 | BFS | [λ±€κ³Ό 사닀리 κ²Œμž„](https://www.acmicpc.net/problem/16928) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/191 |
| 17μ°¨μ‹œ | 2024.05.22 | BFS | [적둝색약](https://www.acmicpc.net/problem/10026) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/195 |

---
3 changes: 2 additions & 1 deletion SeongHoonC/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
| 20μ°¨μ‹œ | 2024.04.07 | DP | <a href="https://www.acmicpc.net/problem/7579">μ•±</a> |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/75 |
| 21μ°¨μ‹œ | 2024.04.11 | DP | <a href="https://www.acmicpc.net/problem/1149">RGB거리</a> |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/77 |
| 22μ°¨μ‹œ | 2024.05.01 | DP | <a href="https://www.acmicpc.net/problem/11053">κ°€μž₯ κΈ΄ μ¦κ°€ν•˜λŠ” λΆ€λΆ„ μˆ˜μ—΄</a> |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/80 |
| 23μ°¨μ‹œ | 2024.05.14 | ??? | <a href="https://www.acmicpc.net/problem/1644">μ†Œμˆ˜μ˜ 연속합</a> |https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/186 |
| 23μ°¨μ‹œ | 2024.05.14 | μ†Œμˆ˜ | <a href="https://www.acmicpc.net/problem/1644">μ†Œμˆ˜μ˜ 연속합</a> |https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/186 |
| 24μ°¨μ‹œ | 2024.05.18| λ°±νŠΈλž˜ν‚Ή | <a href="https://www.acmicpc.net/problem/9663">n-queen</a> |https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/192 |
---
41 changes: 41 additions & 0 deletions SeongHoonC/dfs/nqeen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import java.io.BufferedReader
import java.io.InputStreamReader

var answer = 0
var n: Int = 0
lateinit var board: IntArray
fun main() {
val br = BufferedReader(InputStreamReader(System.`in`))
n = br.readLine().toInt()
board = IntArray(n)
backTracking(0)
println(answer)
}

private fun backTracking(row: Int) {
// row κ°€ μ¦κ°€ν•˜λ‹€κ°€ n μ΄λž‘ 같아지면 μ •λ‹΅ +1
if (row == n) {
answer++
return
}
// row 일 λ•Œ 각 열에 놓을 경우의 수
for (col in 0 until n) {
board[row] = col
// 놓을 수 μžˆλ‹€λ©΄ λ‹€μŒ ν–‰
if (check(row)) backTracking(row + 1)
}
}

private fun check(row: Int): Boolean {
for (i in 0 until row) {
// 행이 κ°™κ±°λ‚˜
if (board[row] == board[i]) {
return false
}
// λŒ€κ°μ„ 
if (row - i == kotlin.math.abs(board[row] - board[i])) {
return false
}
}
return true
}

0 comments on commit dd3422e

Please sign in to comment.