結果

問題 No.173 カードゲーム(Medium)
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-04-04 16:43:05
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 2,449 ms / 3,000 ms
コード長 1,283 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 82,356 KB
最終ジャッジ日時 2023-07-26 17:23:52
合計ジャッジ時間 18,371 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
78,060 KB
testcase_01 AC 472 ms
80,660 KB
testcase_02 AC 2,108 ms
80,812 KB
testcase_03 AC 2,141 ms
80,204 KB
testcase_04 AC 2,089 ms
82,132 KB
testcase_05 AC 1,882 ms
81,232 KB
testcase_06 AC 1,671 ms
79,800 KB
testcase_07 AC 1,558 ms
79,568 KB
testcase_08 AC 1,563 ms
79,836 KB
testcase_09 AC 2,449 ms
82,356 KB
権限があれば一括ダウンロードができます

ソースコード

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