-
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 #25 from AlgorithmWithMe/heejik/5week
[장희직] 킹, 바닥 장식, 빙고, 랜선 자르기, 가로수
- Loading branch information
Showing
5 changed files
with
219 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,36 @@ | ||
package heejik.`5week` | ||
|
||
fun main() { | ||
|
||
val n = readln().toInt() | ||
val tree = mutableListOf<Int>() | ||
val diff = mutableListOf<Int>() | ||
var gcd = 1 | ||
|
||
repeat(n) { | ||
val location = readln().toInt() | ||
if (tree.isNotEmpty()) { | ||
diff.add(location - tree.last()) | ||
} | ||
tree.add(location) | ||
} | ||
|
||
gcd = getGcd(diff[0], diff[1]) | ||
for (i in 2 until diff.size) { | ||
gcd = getGcd(gcd,diff[i]) | ||
} | ||
|
||
println(((tree.last() - tree.first()) / gcd) + 1 - tree.size) | ||
|
||
} | ||
|
||
fun getGcd(_a: Int, _b: Int): Int { | ||
var a = _a | ||
var b = _b | ||
while (b > 0) { | ||
val tmp = a | ||
a = b | ||
b = tmp % b | ||
} | ||
return a | ||
} |
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,46 @@ | ||
package heejik.`5week` | ||
|
||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
import kotlin.system.exitProcess | ||
|
||
val lines = mutableListOf<Long>() | ||
|
||
fun main(): Unit = with(BufferedReader(InputStreamReader(System.`in`))) { | ||
var answer = 0L | ||
val (k, n) = readLine().split(' ').map { it.toInt() } | ||
var s = 0L | ||
|
||
repeat(k) { | ||
val line = readLine().toLong() | ||
lines.add(line) | ||
s += line | ||
} | ||
|
||
var start = 0L | ||
var end = s / n | ||
if (end == 1L) { | ||
println(1) | ||
exitProcess(0) | ||
} | ||
while (start <= end) { | ||
val mid = (end + start) / 2 | ||
val cnt = isCorrect(mid) | ||
if (cnt >= n) { | ||
answer = mid | ||
start = mid + 1 | ||
} else { | ||
end = mid - 1 | ||
} | ||
} | ||
|
||
println(answer) | ||
} | ||
|
||
fun isCorrect(length: Long): Long { | ||
var cnt = 0L | ||
lines.forEach { | ||
cnt += it / length | ||
} | ||
return cnt | ||
} |
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,26 @@ | ||
package heejik.`5week` | ||
|
||
fun main() { | ||
var answer = 0 | ||
|
||
val (n, m) = readln().split(' ').map { it.toInt() } | ||
|
||
val floor = arrayListOf<String>().apply { | ||
repeat(n) { | ||
add(readln()) | ||
} | ||
} | ||
|
||
repeat(n) { i -> | ||
answer += floor[i].split('|').filter { it.isNotEmpty() }.size | ||
} | ||
repeat(m) { j -> | ||
var tmp = "" | ||
repeat(n) { i -> | ||
tmp += floor[i][j] | ||
} | ||
answer += tmp.split('-').filter { it.isNotEmpty() }.size | ||
} | ||
|
||
println(answer) | ||
} |
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,67 @@ | ||
package heejik.`5week` | ||
|
||
import kotlin.system.exitProcess | ||
|
||
val bingo = arrayListOf<MutableList<Int>>() | ||
|
||
fun main() { | ||
var cnt = 0 | ||
var bingoCnt = 0 | ||
val chairMan = arrayListOf<MutableList<Int>>() | ||
|
||
repeat(5) { | ||
bingo.add(readln().split(' ').map { it.toInt() }.toMutableList()) | ||
} | ||
repeat(5) { | ||
chairMan.add(readln().split(' ').map { it.toInt() }.toMutableList()) | ||
} | ||
|
||
chairMan.forEachIndexed { _, ints -> | ||
ints.forEachIndexed { _, num -> | ||
bingo.forEachIndexed { _, row -> | ||
if (num in row) { | ||
cnt += 1 | ||
row[row.indexOf(num)] = -1 | ||
if (isBingo() >= 3) { | ||
println(cnt) | ||
exitProcess(0) | ||
} | ||
bingoCnt = 0 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun isBingo(): Int { | ||
var cnt = 0 | ||
var tmp = 0 | ||
repeat(5) { i -> | ||
if (bingo[i].filter { it == -1 }.size == 5) cnt += 1 | ||
} | ||
|
||
repeat(5) { j -> | ||
tmp = 0 | ||
repeat(5) { i -> | ||
if (bingo[i][j] == -1) { | ||
tmp += 1 | ||
} | ||
if (tmp == 5) cnt += 1 | ||
} | ||
} | ||
|
||
tmp = 0 | ||
repeat(5) { i -> | ||
if (bingo[i][i] == -1) tmp += 1 | ||
} | ||
if (tmp == 5) cnt += 1 | ||
|
||
tmp = 0 | ||
repeat(5) { i -> | ||
if (bingo[i][4 - i] == -1) tmp += 1 | ||
} | ||
if (tmp == 5) cnt += 1 | ||
|
||
return cnt | ||
} | ||
|
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 heejik.`5week` | ||
|
||
|
||
val y = listOf('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H') | ||
val move = listOf("R", "L", "B", "T", "RT", "LT", "RB", "LB") | ||
val dx = listOf(0, 0, -1, 1, 1, 1, -1, -1) | ||
val dy = listOf(1, -1, 0, 0, 1, -1, 1, -1) | ||
|
||
fun main() { | ||
|
||
var (king, rock, n) = readln().split(' ') | ||
|
||
repeat(n.toInt()) { | ||
val location = move.indexOf(readln()) | ||
|
||
var kingX = (king[1].digitToInt()) - 1 | ||
var kingY = y.indexOf(king[0]) | ||
|
||
var rockX = (rock[1].digitToInt()) - 1 | ||
var rockY = y.indexOf(rock[0]) | ||
|
||
val kingNx = kingX + dx[location] | ||
val kingNy = kingY + dy[location] | ||
|
||
|
||
if ((kingNx in 0..7 && kingNy in 0..7).not()) return@repeat | ||
|
||
if (kingNx == rockX && kingNy == rockY) { | ||
val rockNx = rockX + dx[location] | ||
val rockNy = rockY + dy[location] | ||
if ((rockNx in 0..7 && rockNy in 0..7).not()) return@repeat | ||
rockX = rockNx | ||
rockY = rockNy | ||
} | ||
kingX = kingNx | ||
kingY = kingNy | ||
|
||
king = (y[kingY].toString()) + (kingX + 1).toString() | ||
rock = (y[rockY].toString()) + (rockX + 1).toString() | ||
|
||
} | ||
println(king) | ||
println(rock) | ||
} |