1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| import sys sys.setrecursionlimit(100000)
class Node: def __init__(self, ATK, HP, num = 0): self.atk = ATK self.hp = HP self.num = num self.live = True
n,m = map(int, sys.stdin.readline().split()) bob,alix,pj = 0,0,0 ls_a = list(map(int, sys.stdin.readline().split())) ls_b = list(map(int, sys.stdin.readline().split())) for i in range(n): ls_a[i] = Node(ls_a[i], ls_a[i]) for i in range(m): ls_b[i] = Node(ls_b[i], ls_b[i])
def find(ls): """查找这次哪个随从攻击,返回下标""" min_ = 0 idx = 0 for i in range(len(ls)): if ls[i].live: min_ = ls[i].num idx = i break for i in range(len(ls)): if not ls[i].live: continue if ls[i].num == 0 or ls[i].num == min_-1: return i return idx
def dfs(first, p, num_a, num_b): global bob, alix, pj if first: first = not first idx = find(ls_a) for i in range(m): if not ls_b[i].live: continue ls_a[idx].num = ls_a[idx].num + 1 ls_a[idx].hp -= ls_b[i].atk ls_b[i].hp -= ls_a[idx].atk p /= num_b if ls_a[idx].hp <= 0: ls_a[idx].live = False num_a -= 1 if ls_b[i].hp <= 0: ls_b[i].live = False num_b -= 1 if num_a == 0 or num_b == 0: if num_a == 0 and num_b == 0: pj += p elif num_b == 0 and num_a != 0: alix += p elif num_a == 0 and num_b != 0: bob += p if ls_a[idx].live == False: ls_a[idx].live = True num_a += 1 if ls_b[i].live == False: ls_b[i].live = True num_b += 1 ls_a[idx].hp += ls_b[i].atk ls_b[i].hp += ls_a[idx].atk p *= num_b ls_a[idx].num = ls_a[idx].num - 1 continue dfs(first, p, num_a, num_b) if ls_a[idx].live == False: ls_a[idx].live = True num_a += 1 if ls_b[i].live == False: ls_b[i].live = True num_b += 1 ls_a[idx].hp += ls_b[i].atk ls_b[i].hp += ls_a[idx].atk p *= num_b ls_a[idx].num = ls_a[idx].num - 1 else: first = not first idx = find(ls_b) for i in range(n): if not ls_a[i].live: continue ls_b[idx].num = ls_b[idx].num + 1 ls_a[i].hp -= ls_b[idx].atk ls_b[idx].hp -= ls_a[i].atk p = p/num_a if ls_a[i].hp <= 0: ls_a[i].live = False num_a -= 1 if ls_b[idx].hp <= 0: ls_b[idx].live = False num_b -= 1 if num_a == 0 or num_b == 0: if num_a == 0 and num_b == 0: pj += p elif num_b == 0: alix += p elif num_a == 0: bob += p if not ls_a[i].live: ls_a[i].live = True num_a += 1 if not ls_b[idx].live: ls_b[idx].live = True num_b += 1 ls_a[i].hp += ls_b[idx].atk ls_b[idx].hp += ls_a[i].atk ls_b[idx].num = ls_b[idx].num-1 p *= num_a continue dfs(first, p, num_a, num_b) if not ls_a[i].live: ls_a[i].live = True num_a += 1 if not ls_b[idx].live: ls_b[idx].live = True num_b += 1 ls_a[i].hp += ls_b[idx].atk ls_b[idx].hp += ls_a[i].atk ls_b[idx].num = ls_b[idx].num - 1 p *= num_a
first = True if n > m else False if n != m: dfs(first, 1, n, m) elif n == m: dfs(False, 0.5, n, m) dfs(True, 0.5, n, m) ans = alix+bob+pj print(f'{alix/ans:.15g}\n{bob/ans:.15g}\n{pj/ans:.15g}')
|