complete 12015.kt 12738.kt 14626.kt 33985.kt 34029.kt 34060.kt 9252.py
This commit is contained in:
28
storage/zeta/kt/completed/12015.kt
Normal file
28
storage/zeta/kt/completed/12015.kt
Normal file
@@ -0,0 +1,28 @@
|
||||
fun getLengthLIS(arr: List<Int>): Int {
|
||||
val lisProps = mutableListOf<Int>()
|
||||
|
||||
arr.forEach {
|
||||
val x = lisProps.binarySearch(it).let { it ->
|
||||
if (it < 0) {
|
||||
-(it + 1)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
if (x == lisProps.size) {
|
||||
lisProps.add(it)
|
||||
} else {
|
||||
lisProps[x] = it
|
||||
}
|
||||
}
|
||||
|
||||
return lisProps.size
|
||||
}
|
||||
|
||||
|
||||
fun main() {
|
||||
readln()
|
||||
val arr = readln().split(' ').map { it.toInt() }
|
||||
|
||||
println(getLengthLIS(arr))
|
||||
}
|
||||
25
storage/zeta/kt/completed/12738.kt
Normal file
25
storage/zeta/kt/completed/12738.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
import java.io.StreamTokenizer
|
||||
|
||||
fun main() = with(StreamTokenizer(System.`in`.bufferedReader())) {
|
||||
nextToken()
|
||||
val n = nval.toInt()
|
||||
val lisProps = IntArray(n)
|
||||
var size = 0
|
||||
(1..n).forEach { _ ->
|
||||
nextToken()
|
||||
val it = nval.toInt()
|
||||
val x = lisProps.binarySearch(it, 0, size).let { it ->
|
||||
if (it < 0) {
|
||||
-(it + 1)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
if (x == size) {
|
||||
size++
|
||||
}
|
||||
lisProps[x] = it
|
||||
|
||||
}
|
||||
println(size)
|
||||
}
|
||||
44
storage/zeta/kt/completed/14626.kt
Normal file
44
storage/zeta/kt/completed/14626.kt
Normal file
@@ -0,0 +1,44 @@
|
||||
fun getMissingISBN(numbers: List<Int>, missingIndex: Int): Int {
|
||||
val check = numbers.last()
|
||||
|
||||
val others = (numbers.slice(0 until 12).withIndex().sumOf {
|
||||
if (it.index % 2 == 0) {
|
||||
it.value
|
||||
} else {
|
||||
3 * it.value
|
||||
}
|
||||
} + check) % 10
|
||||
val res = if (missingIndex % 2 == 0) {
|
||||
if (others == 0) {
|
||||
0
|
||||
} else {
|
||||
10 - others
|
||||
}
|
||||
} else {
|
||||
if (others == 0) {
|
||||
0
|
||||
} else {
|
||||
if ((10 - others) % 3 == 0) {
|
||||
(10 - others) / 3
|
||||
} else if ((20 - others) % 3 == 0) {
|
||||
(20 - others) / 3
|
||||
} else {
|
||||
(30 - others) / 3
|
||||
}
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
fun main() {
|
||||
var missingIndex = -1
|
||||
val numbers = readln().trim().withIndex().map {
|
||||
if (it.value == '*') {
|
||||
missingIndex = it.index
|
||||
0
|
||||
} else {
|
||||
it.value.digitToInt()
|
||||
}
|
||||
}
|
||||
println(getMissingISBN(numbers, missingIndex))
|
||||
}
|
||||
28
storage/zeta/kt/completed/33985.kt
Normal file
28
storage/zeta/kt/completed/33985.kt
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
평문의 모든 문자는 X이므로 Encrypted Message가 모두 `A` 또는 `B`로 교체되려면,
|
||||
처음과 마지막은 각각 `A`, `B`이어야만 한다.
|
||||
나머지는 구역은 모두 A 또는 B로 바꿀수 있는 방법이 항상 존재한다.
|
||||
```
|
||||
// 가운데 문자를 i번째 문자(S[i])라고 할경우:
|
||||
XXX -> ABX -> AAB (S[i]를 A로 바꾸는 경우)
|
||||
XXX -> ABX -> AAB -> ABB (S[i]를 B로 바꾸는 경우)
|
||||
```
|
||||
|
||||
*/
|
||||
fun isValidEncryption(s: String): Boolean {
|
||||
return s.startsWith('A') && s.endsWith('B')
|
||||
}
|
||||
|
||||
|
||||
fun main() {
|
||||
readln()
|
||||
isValidEncryption(readln().trim()).run {
|
||||
println(
|
||||
if (this) {
|
||||
"Yes"
|
||||
} else {
|
||||
"No"
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
42
storage/zeta/kt/completed/34029.kt
Normal file
42
storage/zeta/kt/completed/34029.kt
Normal file
@@ -0,0 +1,42 @@
|
||||
import java.io.StreamTokenizer
|
||||
import kotlin.math.pow
|
||||
|
||||
|
||||
class BinomialSuccessiveCalculator(val p: Double /* ensure 1 > p > 0*/, val n: Int /*300 >= n >= 1*/) {
|
||||
var cumulative: Double = 0.0
|
||||
var before: Double = 0.0
|
||||
var k: Int = -1
|
||||
|
||||
val p_ratio = p / (1.0 - p)
|
||||
fun next() {
|
||||
|
||||
if (k == -1) {
|
||||
before = (1 - this.p).pow(n)
|
||||
} else {
|
||||
before = before * (n - k).toDouble() / (k + 1).toDouble() * p_ratio
|
||||
}
|
||||
|
||||
cumulative += before
|
||||
k++
|
||||
}
|
||||
|
||||
fun minTrialToTrust(): Int {
|
||||
while (cumulative < 0.05) {
|
||||
next()
|
||||
}
|
||||
return this.k
|
||||
}
|
||||
}
|
||||
|
||||
fun main() = with(StreamTokenizer(System.`in`.bufferedReader())) {
|
||||
nextToken()
|
||||
val 타율 = nval
|
||||
nextToken()
|
||||
val 타석 = nval.toInt()
|
||||
|
||||
|
||||
val bsc = BinomialSuccessiveCalculator(타율, 타석)
|
||||
println(bsc.minTrialToTrust())
|
||||
|
||||
|
||||
}
|
||||
76
storage/zeta/kt/completed/34060.kt
Normal file
76
storage/zeta/kt/completed/34060.kt
Normal file
@@ -0,0 +1,76 @@
|
||||
import java.io.StreamTokenizer
|
||||
|
||||
const val K: Long = 1_000_000_007
|
||||
|
||||
fun find(parents: IntArray, a: Int): Int {
|
||||
if (parents[a] == a) {
|
||||
return a
|
||||
}
|
||||
|
||||
parents[a] = find(parents, parents[a]);
|
||||
|
||||
return parents[a]
|
||||
}
|
||||
|
||||
fun union(parents: IntArray, a: Int, b: Int) {
|
||||
val ra = find(parents, a)
|
||||
val rb = find(parents, b)
|
||||
|
||||
if (ra == rb) {
|
||||
return
|
||||
} else if (ra < rb) {
|
||||
parents[rb] = ra
|
||||
} else {
|
||||
parents[ra] = rb
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun intervalPollutionArea(polluted: List<Long>): Pair<Int, Int> {
|
||||
val n = polluted.size
|
||||
val parents = IntArray(n) { it }
|
||||
val poses = ArrayList<Long>()
|
||||
|
||||
var now_x = 1L
|
||||
var before_y = 0L
|
||||
|
||||
for (p in polluted) {
|
||||
if (p <= before_y) now_x++
|
||||
before_y = p
|
||||
poses.add(K * now_x + p)
|
||||
}
|
||||
|
||||
for ((i, p) in poses.withIndex()) {
|
||||
val px = p / K
|
||||
val py = p % K
|
||||
val dx = listOf(
|
||||
K * (px + 1) + py,
|
||||
p + 1,
|
||||
)
|
||||
|
||||
for (x in dx) {
|
||||
val findPos = poses.binarySearch(x)
|
||||
if (findPos > 0) {
|
||||
union(parents, i, findPos)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Pair(parents.map { find(parents, it) }.distinct().count(), n)
|
||||
}
|
||||
|
||||
fun main() = with(StreamTokenizer(System.`in`.bufferedReader())) {
|
||||
nextToken()
|
||||
val n = nval.toInt()
|
||||
|
||||
val polluted = (1..n).map {
|
||||
nextToken()
|
||||
this.nval.toLong()
|
||||
}
|
||||
|
||||
intervalPollutionArea(polluted).run {
|
||||
println(this.first)
|
||||
println(this.second)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user