Skip to content

Commit 7610299

Browse files
committed
[BOJ] #14717.앉았다 / 실버5 / 80(X)
1 parent 0a56c0a commit 7610299

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Local: 2024-11-07-[BOJ]-#14717-앉았다","url":"/Users/learntosurf/Desktop/codingtest_algorithm_study/learntosurf/BruteForce/2024-11-07-[BOJ]-#14717-앉았다.py","tests":[],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"/Users/learntosurf/Desktop/codingtest_algorithm_study/learntosurf/BruteForce/2024-11-07-[BOJ]-#14717-앉았다.py","group":"local","local":true}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from itertools import combinations
2+
from math import comb
3+
4+
cards = [i for i in range(1, 11)] * 2 # 20장의 카드 리스트 구성 (1~10 2장씩)
5+
6+
def judge(card1, card2):
7+
# 땡: 두 카드가 같을 경우
8+
if card1 == card2:
9+
return f"{card1}땡"
10+
11+
# 끗: 땡이 아닐 경우 두 카드의 합을 10으로 나눈 나머지
12+
else:
13+
sum_value = (card1 + card2) % 10
14+
return f"{sum_value}끗"
15+
16+
# 족보 우선순위 설정 (높은 족보일수록 더 높은 값)
17+
rank_order = {f"{i}땡": 10-i for i in range(1, 11)}
18+
rank_order.update({f"{i}끗": -i for i in range(10)}) # 끗 족보는 숫자가 클수록 강하지만 땡보다는 약함
19+
# 끗 족보에는 음수를 사용해 낮은 값을 할당하여, 땡 족보보다 낮은 순위로 설정
20+
21+
def win_probability(y_card1, y_card2):
22+
win_count = 0
23+
total_count = 0
24+
25+
y_rank = rank_order[judge(y_card1, y_card2)] # 영학이의 족보
26+
27+
# 상대방이 2장을 뽑는 모든 경우의 수
28+
for opp_card1, opp_card2 in combinations(cards, 2):
29+
30+
remaining_cards = cards.copy()
31+
remaining_cards.remove(opp_card1)
32+
remaining_cards.remove(opp_card2)
33+
34+
opp_rank = rank_order[judge(opp_card1, opp_card2)] # 상대방의 족보
35+
36+
total_count += 1
37+
38+
if y_rank > opp_rank: # 영학이가 이기는 경우의 수
39+
win_count += 1
40+
41+
probability = win_count / total_count
42+
return f"{probability:.3f}" # 소수점 셋째 자리까지 출력
43+
44+
y_card1, y_card2 = map(int, input().split())
45+
print(win_probability(y_card1, y_card2))
46+
47+
# print(win_probability(1, 1)) # 0.941
48+
# print(win_probability(1, 2)) # 0.275
49+
# print(win_probability(1, 9)) # 0.000
50+
# print(win_probability(10, 10)) # 1.000

0 commit comments

Comments
 (0)