-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD.py
62 lines (51 loc) · 1.31 KB
/
D.py
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
from collections import Counter
k = int(input())
s = list(input())
t = list(input())
st = s+t
sc = Counter(s)
tc = Counter(t)
total = Counter(st)
s_score = 0
t_score = 0
total = Counter(st)
for i in range(1, 10):
if sc.get(str(i)):
s_score += i*(10**sc[str(i)])
else:
s_score += i
if tc.get(str(i)):
t_score += i*(10**tc[str(i)])
else:
t_score += i
count = {}
for i in range(1, 10):
if not total.get(str(i)):
count[str(i)] = k
else:
count[str(i)] = k - total[str(i)]
ans_u = 0
ans = 0
for i in range(1, 10):
for j in range(1, 10):
tmp_s_score = s_score
if sc.get(str(i)):
tmp_s_score += -i*(10**sc[str(i)]) + i*(10**(sc[str(i)]+1))
else:
tmp_s_score += -i + i*10
tmp_t_score = t_score
if tc.get(str(j)):
tmp_t_score += -j*(10**tc[str(j)]) + j*(10**(tc[str(j)]+1))
else:
tmp_t_score += -j + j*10
if i==j:
ans += count[str(i)]*(count[str(i)]-1)
if tmp_s_score > tmp_t_score:
ans_u += count[str(i)]*(count[str(i)]-1)
else:
ans += count[str(i)]*count[str(j)]
if tmp_s_score > tmp_t_score:
ans_u += count[str(i)]*count[str(j)]
# print(ans_u)
# print(ans)
print(ans_u/ans)