Skip to content

Commit

Permalink
2024-09-04
Browse files Browse the repository at this point in the history
  • Loading branch information
jung0115 committed Sep 4, 2024
1 parent 9f95455 commit 7a1efde
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
3 changes: 2 additions & 1 deletion jung0115/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
| 7차시 | 2024.08.07.수 | 다익스트라 | [지형 이동(Lv.4)](https://school.programmers.co.kr/learn/courses/30/lessons/62050) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/144 |
| 8차시 | 2024.08.19.월 | 이분 탐색 | [입국심사(Lv.3)](https://school.programmers.co.kr/learn/courses/30/lessons/43238) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/148 |
| 9차시 | 2024.08.27.화 | 수학 | [음식 평론가(1188)](https://www.acmicpc.net/problem/1188) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/150 |
| 10차시 | 2024.08.28.수 | 브루트포스 | [램프(1034)](https://www.acmicpc.net/problem/1034) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/151 |
| 10차시 | 2024.08.28.수 | 브루트포스 | [램프(1034)](https://www.acmicpc.net/problem/1034) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/151 |
| 11차시 | 2024.09.04.수 | 수학 | [축구(1344)](https://www.acmicpc.net/problem/1344) | |
37 changes: 37 additions & 0 deletions jung0115/수학/Baekjoon_1344.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 11차시 2024.09.04.수 : 백준 - 축구(1344)
import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.pow

fun combination(n: Int, r: Int): Double {
var result = 1.0
for (i in 0 until r) {
result *= (n - i).toDouble()
result /= (i + 1).toDouble()
}
return result
}

fun probability(p: Double, k: Int): Double {
return combination(18, k) * p.pow(k) * (1 - p).pow(18 - k)
}

fun main() {
// ✅ Input
val br = BufferedReader(InputStreamReader(System.`in`))

var A: Double = br.readLine().toDouble() / 100.0
var B: Double = br.readLine().toDouble() / 100.0

val primeNumbers = setOf(2, 3, 5, 7, 11, 13, 17)
var nonPrimeA = 0.0
var nonPrimeB = 0.0
for (i in 0..18) {
if (i !in primeNumbers) {
nonPrimeA += probability(A, i)
nonPrimeB += probability(B, i)
}
}

print(1 - (nonPrimeA * nonPrimeB))
}
39 changes: 39 additions & 0 deletions jung0115/수학/tempCodeRunnerFile.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 11차시 2024.09.04.수 : 백준 - 축구(1344)
import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.pow

fun combination(n: Int, r: Int): Double {
var result = 1.0
for (i in 0 until r) {
result *= (n - i).toDouble()
result /= (i + 1).toDouble()
}
return result
}

fun probability(p: Double, k: Int): Double {
return combination(18, k) * p.pow(k) * (1 - p).pow(18 - k)
}

fun main() {
// ✅ Input
val br = BufferedReader(InputStreamReader(System.`in`))

var A: Double = br.readLine().toDouble() / 100.0
var B: Double = br.readLine().toDouble() / 100.0

// 2, 3, 5, 7, 11, 13, 17
//val notPrimeNumber = listOf<Int>( 0, 1, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18 )
val primeNumbers = setOf(2, 3, 5, 7, 11, 13, 17)
var nonPrimeA = 0.0
var nonPrimeB = 0.0
for (i in 0..18) {
if (i !in primeNumbers) {
nonPrimeA += probability(A, i)
nonPrimeB += probability(B, i)
}
}

print(1 - (nonPrimeA * nonPrimeB))
}

0 comments on commit 7a1efde

Please sign in to comment.