-
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 #99 from wellFoundedDevelopers/byeonghee/23week
[소병희] 센서, 로봇 청소기, 합분해, 보물섬
- Loading branch information
Showing
4 changed files
with
183 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,63 @@ | ||
package byeonghee.`23week` | ||
|
||
import java.io.* | ||
|
||
class 소병희_로봇청소기 { | ||
|
||
companion object { | ||
const val DIRTY = 0 | ||
const val WALL = 1 | ||
const val CLEAR = 2 | ||
|
||
val dr = arrayOf(-1, 0, 1, 0) | ||
val dc = arrayOf(0, 1, 0, -1) | ||
|
||
fun solve() : Unit = with(BufferedReader(InputStreamReader(System.`in`))) { | ||
val (n, m) = readLine().split(" ").map { it.toInt() } | ||
var (r, c, d) = readLine().split(" ").map { it.toInt() } | ||
val room = Array(n) { IntArray(m) } | ||
|
||
for(r in 0 until n) { | ||
readLine().split(" ").forEachIndexed { c, v -> | ||
room[r][c] = v.toInt() | ||
} | ||
} | ||
|
||
var stop = false | ||
var back = false | ||
var cleaned = 0 | ||
while(stop.not()) { | ||
if (room[r][c] == DIRTY) { | ||
cleaned++ | ||
room[r][c] = CLEAR | ||
} | ||
|
||
back = true | ||
for (i in 0 until 4) { | ||
d = (d + 3) % 4 | ||
if (room[r + dr[d]][c + dc[d]] == DIRTY) { | ||
r += dr[d] | ||
c += dc[d] | ||
back = false | ||
break | ||
} | ||
} | ||
if (back.not()) continue | ||
|
||
if (room[r - dr[d]][c - dc[d]] == WALL) { | ||
stop = true | ||
} | ||
else { | ||
r -= dr[d] | ||
c -= dc[d] | ||
} | ||
} | ||
|
||
println(cleaned) | ||
} | ||
} | ||
} | ||
|
||
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,57 @@ | ||
package byeonghee.`23week` | ||
|
||
import java.io.* | ||
|
||
class 소병희_보물섬 { | ||
|
||
companion object { | ||
data class Trip(val r: Int, val c: Int, val dist: Int) | ||
|
||
val dr = arrayOf(-1, 0, 1, 0) | ||
val dc = arrayOf(0, 1, 0, -1) | ||
|
||
fun solve(): Unit = with(BufferedReader(InputStreamReader(System.`in`))) { | ||
val (h, w) = readLine().split(" ").map { it.toInt() } | ||
val treasureMap = Array(h + 2) { CharArray(w + 2) { 'W' } } | ||
val queue = ArrayDeque<Trip>() | ||
var answer = 0 | ||
var trip: Trip | ||
var nxtR = 0 | ||
var nxtC = 0 | ||
|
||
for(r in 1 until h + 1) { | ||
readLine().forEachIndexed { c, v -> | ||
treasureMap[r][c + 1] = v | ||
} | ||
} | ||
|
||
for(r in 1 until h + 2) for(c in 1 until w + 2) { | ||
if (treasureMap[r][c] == 'W') continue | ||
val visited = Array(h + 2) { BooleanArray(w + 2) } | ||
queue.add(Trip(r, c, 0)) | ||
|
||
while(queue.isNotEmpty()) { | ||
trip = queue.removeFirst() | ||
if (visited[trip.r][trip.c]) continue | ||
|
||
answer = maxOf(answer, trip.dist) | ||
visited[trip.r][trip.c] = true | ||
|
||
for(d in 0 until 4) { | ||
nxtR = trip.r + dr[d] | ||
nxtC = trip.c + dc[d] | ||
if (treasureMap[nxtR][nxtC] == 'W') continue | ||
|
||
queue.add(Trip(nxtR, nxtC, trip.dist + 1)) | ||
} | ||
} | ||
} | ||
|
||
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,38 @@ | ||
package byeonghee.`23week` | ||
|
||
import java.io.* | ||
import java.util.* | ||
|
||
class 소병희_센서 { | ||
|
||
companion object { | ||
fun solve(): Unit = with(BufferedReader(InputStreamReader(System.`in`))) { | ||
val n = readLine().toInt() | ||
val k = readLine().toInt() | ||
val sensors = readLine().split(" ").map { it.toInt() }.sorted() | ||
var answer = sensors.last() - sensors.first() | ||
|
||
if (n == 1) { | ||
println(0) | ||
return | ||
} | ||
|
||
val pq = PriorityQueue<Int>(n - 1, Collections.reverseOrder()) | ||
|
||
for(i in 1 until n) { | ||
pq.add(sensors[i] - sensors[i - 1]) | ||
} | ||
|
||
for(i in 0 until k - 1) { | ||
if (pq.isEmpty()) break | ||
answer -= pq.poll() | ||
} | ||
|
||
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,25 @@ | ||
package byeonghee.`23week` | ||
|
||
import java.io.* | ||
|
||
class 소병희_합분해 { | ||
|
||
companion object { | ||
const val MOD = 1_000_000_000 | ||
|
||
fun solve(): Unit = with(BufferedReader(InputStreamReader(System.`in`))) { | ||
val (n, k) = readLine().split(" ").map { it.toInt() } | ||
val dp = Array(n + 1) { IntArray(k) { 1 } } | ||
|
||
for(r in 1 .. n) for(c in 1 until k) { | ||
dp[r][c] = (dp[r - 1][c] + dp[r][c - 1]) % MOD | ||
} | ||
|
||
println(dp[n][k - 1]) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
소병희_합분해.solve() | ||
} |