-
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 #270 from wellFoundedDevelopers/byeonghee/64week
[소병희] - 내리막 길, 치즈, 가장 긴 증가하는 부분 수열 4, 삼각 달팽이
- Loading branch information
Showing
4 changed files
with
180 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,35 @@ | ||
package byeonghee.week64 | ||
|
||
class `소병희_가장 긴 증가하는 부분 수열 4` { | ||
companion object { | ||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val n = readLine().toInt() | ||
val arr = IntArray(n) | ||
val dp = Array(n) { mutableListOf<Int>() } | ||
var answer = 0 | ||
|
||
readLine().split(" ").forEachIndexed { i, v -> arr[i] = v.toInt() } | ||
|
||
dp[0].add(arr[0]) | ||
for(i in 1 until n) { | ||
var idx = i | ||
for(j in i - 1 downTo 0) { | ||
if (dp[j].last() < arr[i] && dp[j].size > dp[idx].size) { | ||
idx = j | ||
} | ||
} | ||
if (idx != i) dp[i].addAll(dp[idx]) | ||
dp[i].add(arr[i]) | ||
|
||
if (dp[i].size > dp[answer].size) answer = i | ||
} | ||
|
||
println(dp[answer].size) | ||
println(dp[answer].joinToString(" ")) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
`소병희_가장 긴 증가하는 부분 수열 4`.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,44 @@ | ||
package byeonghee.week64 | ||
|
||
class 소병희_내리막길 { | ||
companion object { | ||
val dr = intArrayOf(0, 1, 0, -1) | ||
val dc = intArrayOf(1, 0, -1, 0) | ||
|
||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val (m, n) = readLine().split(" ").map { it.toInt() } | ||
val map = Array(m) { IntArray(n) } | ||
val visited = Array(m) { IntArray(n) { -1 } } | ||
|
||
repeat(m) { i -> | ||
readLine().split(" ").forEachIndexed { j, v -> | ||
map[i][j] = v.toInt() | ||
} | ||
} | ||
|
||
visited[m-1][n-1] = 1 | ||
|
||
fun dfs(r: Int, c: Int): Int { | ||
if (visited[r][c] > -1) return visited[r][c] | ||
|
||
visited[r][c] = 0 | ||
for(d in 0 until 4) { | ||
val nr = r + dr[d] | ||
val nc = c + dc[d] | ||
if (nr !in 0 until m || nc !in 0 until n) continue | ||
if (map[nr][nc] >= map[r][c]) continue | ||
|
||
visited[r][c] += dfs(nr, nc) | ||
} | ||
|
||
return visited[r][c] | ||
} | ||
|
||
println(dfs(0, 0)) | ||
} | ||
} | ||
} | ||
|
||
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,41 @@ | ||
package byeonghee.week64 | ||
|
||
class `소병희_삼각 달팽이` { | ||
fun solution(n: Int): IntArray { | ||
var answer: IntArray = intArrayOf() | ||
|
||
val triangle = Array(n) { ArrayDeque<Int>() } | ||
var side = n | ||
var round = 0 | ||
var sl = 0 | ||
var count = 1 | ||
|
||
while(side > 0) { | ||
for(i in sl until sl + side) { | ||
triangle[i].add(round, count++) | ||
} | ||
|
||
repeat(side - 1) { i -> | ||
triangle[sl + side - 1].add(round + i + 1, count++) | ||
} | ||
|
||
for(i in sl + side-2 downTo sl + 1) { | ||
triangle[i].add(triangle[i].size - round, count++) | ||
} | ||
|
||
round++ | ||
side -= 3 | ||
sl += 2 | ||
} | ||
|
||
return triangle.flatMap { it.toList() }.toIntArray() | ||
} | ||
} | ||
|
||
fun main() { | ||
val sol = `소병희_삼각 달팽이`() | ||
println(sol.solution(4).joinToString(" ")) | ||
println(sol.solution(5).joinToString(" ")) | ||
println(sol.solution(6).joinToString(" ")) | ||
println(sol.solution(7).joinToString(" ")) | ||
} |
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,60 @@ | ||
package byeonghee.week64 | ||
|
||
class 소병희_치즈 { | ||
companion object { | ||
val dr = intArrayOf(0, 1, 0, -1) | ||
val dc = intArrayOf(1, 0, -1, 0) | ||
|
||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val (n, m) = readLine().split(" ").map { it.toInt() } | ||
val paper = Array(n) { IntArray(m) } | ||
var airContact = Array(n) { IntArray(m) } | ||
val q = ArrayDeque<IntArray>() | ||
var time = 0 | ||
var cheese = 0 | ||
|
||
repeat(n) { i -> | ||
readLine().split(" ").forEachIndexed { j, v -> | ||
paper[i][j] = v.toInt().also { if (it == 1) cheese++ } | ||
} | ||
} | ||
|
||
fun checkAir() { | ||
airContact = Array(n) { IntArray(m) } | ||
airContact[0][0]++ | ||
q.add(intArrayOf(0, 0)) | ||
|
||
while(q.isNotEmpty()) { | ||
val (r, c) = q.removeFirst() | ||
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 m) continue | ||
if (paper[nr][nc] == 0 && airContact[nr][nc] > 0) continue | ||
|
||
airContact[nr][nc]++ | ||
if (paper[nr][nc] == 1) continue | ||
q.add(intArrayOf(nr, nc)) | ||
} | ||
} | ||
} | ||
|
||
while(cheese > 0) { | ||
checkAir() | ||
for(i in 0 until n) for(j in 0 until m) { | ||
if (paper[i][j] == 1 && airContact[i][j] >= 2) { | ||
paper[i][j] = 0 | ||
cheese-- | ||
} | ||
} | ||
time++ | ||
} | ||
|
||
println(time) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
소병희_치즈.solve() | ||
} |