-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from wellFoundedDevelopers/byeonghee/46week
[소병희] 숨바꼭질3
- Loading branch information
Showing
4 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package byeonghee.week46 | ||
|
||
class 소병희_경주로건설 { | ||
|
||
var ans = 0 | ||
var n = 0 | ||
lateinit var board: Array<IntArray> | ||
lateinit var visited: Array<BooleanArray> | ||
|
||
val dr = intArrayOf(0, 1, 0, -1) | ||
val dc = intArrayOf(1, 0, -1, 0) | ||
|
||
fun solution(_board: Array<IntArray>): Int { | ||
board = _board | ||
n = _board.size | ||
ans = n * n * 500 | ||
visited = Array(n) { BooleanArray(n) } | ||
for(d in 0 until 4) { | ||
val nr = dr[d] | ||
val nc = dc[d] | ||
if (nr !in 0 until n || nc !in 0 until n) continue | ||
if (board[nr][nc] == 1 || visited[nr][nc]) continue | ||
|
||
visited[nr][nc] = true | ||
dfs(d, nr, nc, 100) | ||
visited[nr][nc] = false | ||
} | ||
return ans | ||
} | ||
|
||
fun dfs(from: Int, r: Int, c: Int, cost: Int) { | ||
if (r == n-1 && c == n-1) { | ||
ans = minOf(ans, cost) | ||
return | ||
} | ||
|
||
for(d in 0 until 4) { | ||
val nr = r + dr[d] | ||
val nc = c + dc[d] | ||
if (nr !in 0 until n || nc !in 0 until n) continue | ||
if (board[nr][nc] == 1 || visited[nr][nc]) continue | ||
|
||
visited[nr][nc] = true | ||
val ncost = cost + if ((from + d) % 2 == 0) 100 else 600 | ||
dfs(d, nr, nc, ncost) | ||
visited[nr][nc] = false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package byeonghee.week46 | ||
|
||
class 소병희_농장관리 { | ||
|
||
companion object { | ||
val dr = intArrayOf(-1, -1, -1, 0, 0, 1, 1, 1) | ||
val dc = intArrayOf(-1, 0, 1, -1, 1, -1, 0, 1) | ||
|
||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val (n, m) = readLine().split(" ").map { it.toInt() } | ||
val farm = Array(n) { IntArray(m) } | ||
val notTop = Array(n) { BooleanArray(m) } | ||
val isTop = Array(n) { BooleanArray(m) } | ||
var answer = 0 | ||
|
||
repeat(n) { i -> | ||
readLine().split(" ").forEachIndexed { j, v -> | ||
farm[i][j] = v.toInt() | ||
} | ||
} | ||
|
||
row@ for(r in 0 until n) { | ||
col@ for(c in 0 until m) { | ||
if (notTop[r][c] || isTop[r][c]) continue | ||
|
||
var same = 0 | ||
for(d in 0 until 8) { | ||
val nr = r + dr[d] | ||
val nc = c + dc[d] | ||
if (nr !in 0 until n || nc !in 0 until m) continue | ||
if (farm[nr][nc] > farm[r][c]) continue@col | ||
if (farm[nr][nc] == farm[r][c] && isTop[nr][nc]) { | ||
isTop[r][c] = true | ||
continue@col | ||
} | ||
if (farm[nr][nc] == farm[r][c] && notTop[nr][nc]) { | ||
notTop[r][c] = true | ||
continue@col | ||
} | ||
if (farm[nr][nc] == farm[r][c]) same++ | ||
if (same > 1) continue@col | ||
} | ||
|
||
answer++ | ||
isTop[r][c] = true | ||
|
||
for(d in 0 until 8) { | ||
val nr = r + dr[d] | ||
val nc = c + dc[d] | ||
if (nr !in 0 until n || nc !in 0 until m) continue | ||
if (farm[nr][nc] == farm[r][c]) isTop[nr][nc] = true | ||
else notTop[nr][nc] = true | ||
} | ||
} | ||
} | ||
|
||
println(answer) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
소병희_농장관리.solve() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package byeonghee.week46 | ||
|
||
val number = intArrayOf( | ||
"1110111".toInt(2), | ||
"0010010".toInt(2), | ||
"1011101".toInt(2), | ||
"1011011".toInt(2), | ||
"0111010".toInt(2), | ||
"1101011".toInt(2), | ||
"1101111".toInt(2), | ||
"1010010".toInt(2), | ||
"1111111".toInt(2), | ||
"1111011".toInt(2) | ||
) | ||
|
||
fun main() = with(System.`in`.bufferedReader()) { | ||
val (n, k, p, x) = readLine().split(" ").map { it.toInt() } | ||
val cases = Array(p) { IntArray(10) } | ||
val digit = x.toString().length | ||
val q = ArrayDeque<IntArray>() | ||
|
||
for(i in 0 .. 9) { | ||
for(j in 0 .. 9) { | ||
if (i == j) continue | ||
val change = countOnes(i.xor(j)) | ||
if (change > p) continue | ||
cases[change][i]++ | ||
} | ||
} | ||
|
||
// 조합...하기 | ||
} | ||
|
||
fun countOnes(n: Int) : Int { | ||
var ans = 0 | ||
var offset = 1 | ||
while(offset <= n) { | ||
if (n and offset == 1) ans++ | ||
offset *= 2 | ||
} | ||
return ans | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package byeonghee.week46 | ||
|
||
class 소병희_숨바꼭질3 { | ||
|
||
companion object { | ||
const val INF = 999_999 | ||
|
||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val (n, k) = readLine().split(" ").map { it.toInt() } | ||
|
||
if (n >= k) { | ||
println(n - k) | ||
return@with | ||
} | ||
|
||
val dp = IntArray(100_001) { it - n } | ||
repeat(n) { i -> dp[i] = n - i } | ||
|
||
for(i in n .. maxOf(k, n * 2).coerceAtMost(100_000)) { | ||
if (i > 0) dp[i] = minOf(dp[i], dp[i-1] + 1) | ||
if (i < 100_000) dp[i] = minOf(dp[i], dp[i+1] + 1) | ||
if (i%2 == 0) dp[i] = minOf(dp[i], dp[i/2]) | ||
|
||
if (i <= 50_000) dp[i*2] = minOf(dp[i*2], dp[i]) | ||
if (i > 0) dp[i-1] = minOf(dp[i-1], dp[i] + 1) | ||
if (i < 100_000) dp[i+1] = minOf(dp[i+1], dp[i] + 1) | ||
} | ||
|
||
println(dp[k]) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
소병희_숨바꼭질3.solve() | ||
} |