Problem:


Score : 1000 points

Problem Statement

   #nck {
      width: 30px;
      height: auto;
   }

There are two (6-sided) dice: a red die and a blue die.
When a red die is rolled, it shows i with probability p_i percents, and when a blue die is rolled, it shows j with probability q_j percents.

Petr and tourist are playing the following game.
Both players know the probabilistic distributions of the two dice.
First, Petr chooses a die in his will (without showing it to tourist), rolls it, and tells tourist the number it shows.
Then, tourist guesses the color of the chosen die.
If he guesses the color correctly, tourist wins. Otherwise Petr wins.

If both players play optimally, what is the probability that tourist wins the game?

Constraints

0 ≤ p_i, q_i ≤ 100

p_1 + ... + p_6 = q_1 + ... + q_6 = 100

All values in the input are integers.

Input

The input is given from Standard Input in the following format:

p_1 p_2 p_3 p_4 p_5 p_6
q_1 q_2 q_3 q_4 q_5 q_6

Output

Print the probability that tourist wins.
The absolute error or the relative error must be at most 10^{-9}.

Sample Input 1

25 25 25 25 0 0
0 0 0 0 50 50

Sample Output 1

1.000000000000

tourist can always win the game: If the number is at most 4, the color is definitely red. Otherwise the color is definitely blue.

Sample Input 2

10 20 20 10 20 20
20 20 20 10 10 20

Sample Output 2

0.550000000000



Sample input:
25 25 25 25 0 0
0 0 0 0 50 50


Sample output:
1.000000000000

Submission status: Wrong Answer

Solution code:
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
select_p, select_q, even = 0, 0, 0
for p, q in zip(P, Q):
  if p > q:
    select_p += p
  elif p < q:
    select_q += q
  else:
    even += p
ans = min(select_p, select_q) + even/2
ans /= 100
print(ans)

Submission status: Wrong Answer

Solution code:
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
select_p, select_q, even = 0, 0, 0
for p, q in zip(P, Q):
  if p > q:
    select_p += p
  elif p < q:
    select_q += q
  else:
    even += p
print(min(select_p, select_q) + even/2)

Submission status: Wrong Answer

Solution code:
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
select_p, select_q, even = 0, 0, 0
for p, q in zip(P, Q):
  if p > q:
    select_p += p
  elif p < q:
    select_q += q
  else:
    even += p
ans = 0
if select_p < select_q:
  for p, q in zip(P, Q):
    if p > q:
      ans += p
    elif p == q:
      ans += p/2
else:
  for p, q in zip(P, Q):
    if p < q:
      ans += q
    elif p == q:
      ans += p/2
ans /= 100
print(ans)

Submission status: Wrong Answer

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline

from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	p = getlist()
	q = getlist()
	t1 = 0
	t2 = 0
	for i in range(6):
		if p[i] > q[i]:
			t1 += p[i] / 100
		elif p[i] < q[i]:
			t2 += q[i] / 100
		else:
			t1 += p[i] / 200
			t2 += q[i] / 200
	print(max(t1, t2))

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline

from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	p = getlist()
	q = getlist()
	t1 = 0
	t2 = 0
	for i in range(6):
		if p[i] > q[i]:
			t1 += p[i] / 100
		elif p[i] < q[i]:
			t2 += q[i] / 100
		else:
			t1 += p[i] / 200
			t2 += q[i] / 200
	print(min(t1, t2))

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mean = 0
for i in range(6):
  mean += (1/2)*max(a[i],b[i])
print("%.12f" % (mean/100))

Submission status: Wrong Answer

Solution code:
r = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = sum(abs(r[i]-b[i]) for i in range(6))
print(diff/400 + 0.5)

Submission status: Wrong Answer

Solution code:
import math

a = map(float, raw_input().split())
b = map(float, raw_input().split())
n = len(a)
d1 = 0.0
d2 = 0.0
for i in range(n):
    if a[i] + b[i] == 0:
        continue
    c = max(a[i], b[i]) / (a[i] + b[i])
    d1 += c * a[i] / 100.0
    d2 += c * b[i] / 100.0

print 2 * d1 * d2 / (d1 + d2)

Submission status: Wrong Answer

Solution code:
import math

a = map(float, raw_input().split())
b = map(float, raw_input().split())
n = len(a)
d1 = 0.0
d2 = 0.0
for i in range(n):
    if a[i] + b[i] == 0:
        continue
    c = max(a[i], b[i]) / (a[i] + b[i])
    d1 += c * a[i] / 100.0
    d2 += c * b[i] / 100.0

print math.sqrt(d1*d2)

Submission status: Wrong Answer

Solution code:
a = map(float, raw_input().split())
b = map(float, raw_input().split())
n = len(a)
d1 = 0.0
d2 = 0.0
for i in range(n):
    if a[i] + b[i] == 0:
        continue
    c = max(a[i], b[i]) / (a[i] + b[i])
    d1 += c * a[i] / 100.0
    d2 += c * b[i] / 100.0

print (d1 + d2) / 2

Submission status: Wrong Answer

Solution code:
a = map(float, raw_input().split())
b = map(float, raw_input().split())
n = len(a)
d1 = 0.0
d2 = 0.0
for i in range(n):
    if a[i] + b[i] == 0:
        continue
    c = max(a[i], b[i]) / (a[i] + b[i])
    d1 += c * a[i] / 100.0
    d2 += c * b[i] / 100.0

res = 0.0
if d1 <= d2:
    for i in range(n):
        if a[i] + b[i] == 0:
            continue
        res += a[i] / 100.0 * max(a[i], b[i]) / (a[i] + b[i])
else:
    for i in range(n):
        if a[i] + b[i] == 0:
            continue
        res += b[i] / 100.0 * max(a[i], b[i]) / (a[i] + b[i])

print res

Submission status: Wrong Answer

Solution code:
a = map(float, raw_input().split())
b = map(float, raw_input().split())
n = len(a)
d1 = 0.0
d2 = 0.0
for i in range(n):
    if a[i] + b[i] == 0:
        continue
    c = max(a[i], b[i]) / (a[i] + b[i])
    d1 += c * a[i] / 100.0
    d2 += c * b[i] / 100.0

res = 0.0
if d1 <= d2:
    for i in range(n):
        res += a[i] / 100.0 * max(a[i], b[i]) / (a[i] + b[i])
else:
    for i in range(n):
        res += b[i] / 100.0 * max(a[i], b[i]) / (a[i] + b[i])

print res

Submission status: Wrong Answer

Solution code:
P = map(int, raw_input().split())
Q = map(int, raw_input().split())
suA = suB = 0
for i in xrange(6):
    if P[i] > Q[i]:
        suA += P[i]/100.
    if P[i] < Q[i]:
        suB += Q[i]/100.
    if P[i] == Q[i]:
        suA += P[i]/200.
        suB += Q[i]/200.
print min(suA, suB)

Submission status: Wrong Answer

Solution code:
a = map(float, raw_input().split())
b = map(float, raw_input().split())
n = len(a)
d1 = 0.0
d2 = 0.0
for i in range(n):
    if a[i] + b[i] == 0:
        continue
    c = max(a[i], b[i]) / (a[i] + b[i])
    d1 += c * a[i] / 100.0
    d2 += c * b[i] / 100.0

print max(d1, d2)

Submission status: Wrong Answer

Solution code:
a = map(float, raw_input().split())
b = map(float, raw_input().split())
n = len(a)
d1 = 0.0
d2 = 0.0
for i in range(n):
    c = max(a[i], b[i]) / (a[i] + b[i])
    d1 += c * a[i] / 100.0
    d2 += c * b[i] / 100.0

print max(d1, d2)

Submission status: Wrong Answer

Solution code:
a = [int(i) for i in raw_input().split()]
b = [int(i) for i in raw_input().split()]
p1 = p2 = 0
for i in range(6):
    if a[i] > b[i]:
        p1 += a[i]
    elif a[i] == b[i]:
        p1 += a[i] * 1.0 / 2
        p2 += b[i] * 1.0 / 2
    else:
        p2 += b[i]
print min(p1 / 100.0, p2 / 100.0)

Submission status: Wrong Answer

Solution code:
a = [int(i) for i in raw_input().split()]
b = [int(i) for i in raw_input().split()]
p1 = p2 = 0
for i in range(6):
    if a[i] > b[i]:
        p1 += a[i]
    elif a[i] == b[i]:
        p1 += a[i] * 1.0 / 2
        p2 += b[i] * 1.0 / 2
    else:
        p2 += b[i]
print min(p1 / 100, p2 / 100)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

P = [int(x) for x in readline().split()]
Q = [int(x) for x in readline().split()]

def tour_win_rate(x):
    if x<0: return 1000
    if x>1: return 1000
    # petrが、Pをx、Qを1-xで選ぶとする。
    return sum(max(p*x,q*(1-x)) for p,q in zip(P,Q))/100

from scipy.optimize import fmin

xopt = fmin(tour_win_rate,x0=0.5,disp=False,xtol=1e-10)[0]
print(tour_win_rate(xopt))

Submission status: Accepted

Solution code:
import math as m

# f = open('input', 'r')
# P = list(map(lambda x: float(x)/100, f.readline().split()))
# Q = list(map(lambda x: float(x)/100, f.readline().split()))
P = list(map(lambda x: float(x)/100, input().split()))
Q = list(map(lambda x: float(x)/100, input().split()))


def calc(x):
    prob = [max(p*x, q*(1-x)) for p, q in zip(P, Q)]
    return sum(prob)

phi = (1 + m.sqrt(5)) / 2
l, r = 0, 1
x1, x2 = (l*phi + r)/(1 + phi), (l + r*phi)/(1 + phi)
f1, f2 = calc(x1), calc(x2)

while True:
    if f1 > f2:
        l, x1 = x1, x2
        x2 = (l + r*phi)/(1 + phi)
        f1, f2 = f2, calc(x2)
    else:
        x2, r = x1, x2
        x1 = (l*phi + r)/(1 + phi)
        f1, f2 = calc(x1), f1

    if abs(l-r) < 1e-12:
        break
print('%.12lf' % f1)

Submission status: Accepted

Solution code:
a = [int(i) for i in raw_input().split()]
b = [int(i) for i in raw_input().split()]
c = [(a[i]/100.0,b[i]/100.0,(a[i]+b[i])/100.0,a[i]*1.0/(a[i]+b[i])) for i in range(len(a)) if a[i]+b[i]>0]
n = len(c)
c.sort(key=lambda item: item[3], reverse=True)
u = [0] * n
res = 1
for i in range(n):
    du = min(res / (c[i][2]), 1)
    u[i] = du
    res -= du * c[i][2]
    if res <=0:
        break
ans = 0
for i in range(n):
    ans += c[i][0] * u[i]

print ans

Submission status: Runtime Error

Solution code:
a = [int(i) for i in raw_input().split()]
b = [int(i) for i in raw_input().split()]
n = len(a)
c = [(a[i]/100.0,b[i]/100.0,(a[i]+b[i])/100.0,a[i]*1.0/(a[i]+b[i]+1e-10)) for i in range(n)]
c.sort(key=lambda item: item[3], reverse=True)
u = [0] * n
res = 1
for i in range(n):
    du = min(res / (c[i][2]), 1)
    u[i] = du
    res -= du * c[i][2]
    if res <=0:
        break
ans = 0
for i in range(n):
    ans += c[i][0] * u[i]

print ans

Submission status: Runtime Error

Solution code:
a = [int(i) for i in raw_input().split()]
b = [int(i) for i in raw_input().split()]
n = len(a)
c = [(a[i]/100.0,b[i]/100.0,(a[i]+b[i])/100.0,a[i]*1.0/(a[i]+b[i])) for i in range(n)]
c.sort(key=lambda item: item[3], reverse=True)
u = [0] * n
res = 1
for i in range(n):
    du = min(res / (c[i][2]), 1)
    u[i] = du
    res -= du * c[i][2]
    if res <=0:
        break
ans = 0
for i in range(n):
    ans += c[i][0] * u[i]

print ans