結果
| 問題 |
No.173 カードゲーム(Medium)
|
| コンテスト | |
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2016-04-04 16:44:27 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,360 ms / 3,000 ms |
| コード長 | 1,278 bytes |
| コンパイル時間 | 148 ms |
| コンパイル使用メモリ | 82,112 KB |
| 実行使用メモリ | 78,648 KB |
| 最終ジャッジ日時 | 2024-10-03 04:12:02 |
| 合計ジャッジ時間 | 9,653 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#!/usr/bin/env pypy3
# -*- coding: utf-8 -*-
import random
MAX_TRIAL = 160000
def use_card(l, p, cards):
if l == 1:
return cards.pop()
else:
cards.sort()
judge = random.random()
if judge <= p:
return cards.pop(0)
else:
return cards.pop(random.randint(1, l - 1))
def simulate(pa, pb, a_cards, b_cards):
a_score = 0
b_score = 0
a_cards_copy = a_cards[:]
b_cards_copy = b_cards[:]
l = len(a_cards)
while a_cards_copy and b_cards_copy:
a_card = use_card(l, pa, a_cards_copy)
b_card = use_card(l, pb, b_cards_copy)
sum_card = a_card + b_card
if a_card > b_card:
a_score += sum_card
elif b_card > a_card:
b_score += sum_card
l -= 1
return 1 if a_score > b_score else 0
def compute_probability(pa, pb, a_cards, b_cards, trial=MAX_TRIAL):
f = lambda: simulate(pa, pb, a_cards, b_cards)
return sum(f() for _ in range(trial)) / trial
def main():
_, pa, pb = map(float, input().split())
a_cards = list(map(int, input().split()))
b_cards = list(map(int, input().split()))
print("{:.12f}".format(compute_probability(pa, pb, a_cards, b_cards)))
if __name__ == '__main__':
main()
はむ吉🐹