結果

問題 No.173 カードゲーム(Medium)
ユーザー はむ吉🐹
提出日時 2016-04-04 16:43:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,265 ms / 3,000 ms
コード長 1,283 bytes
コンパイル時間 1,113 ms
コンパイル使用メモリ 81,976 KB
実行使用メモリ 78,744 KB
最終ジャッジ日時 2024-10-03 04:11:21
合計ジャッジ時間 16,298 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3
# -*- coding: utf-8 -*-

import random


MAX_TRIAL = 3 * 10 ** 5


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()
0