← Home
package main

import (
	"fmt"
)

func step(dp, newDp, pref []float64, hp int, trans0 float64, l int, r int, probX float64) float64 {
	destroyed := 0.0

	pref[0] = 0.0
	for i := 0; i < hp; i++ {
		pref[i+1] = pref[i] + dp[i]
		newDp[i] = dp[i] * trans0
	}

	for i := 0; i < hp; i++ {
		minJ := i - r
		maxJ := i - l
		if maxJ >= 0 {
			if minJ < 0 {
				minJ = 0
			}
			sum := pref[maxJ+1] - pref[minJ]
			newDp[i] += sum * probX
		}
	}

	for j := 0; j < hp; j++ {
		if dp[j] == 0 {
			continue
		}
		minD := hp - j
		if minD < l {
			minD = l
		}
		if minD <= r {
			count := float64(r - minD + 1)
			destroyed += dp[j] * count * probX
		}
	}

	return destroyed
}

func main() {
	var hpA, dtA, lA, rA, pA int
	var hpB, dtB, lB, rB, pB int

	if _, err := fmt.Scan(&hpA, &dtA, &lA, &rA, &pA); err != nil {
		return
	}
	if _, err := fmt.Scan(&hpB, &dtB, &lB, &rB, &pB); err != nil {
		return
	}

	if pA == 100 {
		fmt.Printf("%.6f\n", 0.0)
		return
	}

	transA0 := float64(pA) / 100.0
	probAX := (1.0 - transA0) / float64(rA-lA+1)

	transB0 := float64(pB) / 100.0
	probBX := (1.0 - transB0) / float64(rB-lB+1)

	dpA := make([]float64, hpB)
	nextDpA := make([]float64, hpB)
	prefA := make([]float64, hpB+1)
	dpA[0] = 1.0

	dpB := make([]float64, hpA)
	nextDpB := make([]float64, hpA)
	prefB := make([]float64, hpA+1)
	dpB[0] = 1.0

	totalDestroyedB := 0.0
	totalDestroyedA := 0.0

	ans := 0.0
	mCurrent := 0

	for k := 1; ; k++ {
		countB := 0
		if k > 1 {
			timeA := (k - 1) * dtA
			countB = (timeA-1)/dtB + 1
		}

		for mCurrent < countB {
			destroyed := step(dpB, nextDpB, prefB, hpA, transB0, lB, rB, probBX)
			dpB, nextDpB = nextDpB, dpB
			totalDestroyedB += destroyed
			mCurrent++
		}

		sBM := 1.0 - totalDestroyedB
		if sBM < 0 {
			sBM = 0
		}

		fAK := step(dpA, nextDpA, prefA, hpB, transA0, lA, rA, probAX)
		dpA, nextDpA = nextDpA, dpA
		totalDestroyedA += fAK

		ans += fAK * sBM

		sumDpA := 1.0 - totalDestroyedA
		if sumDpA < 1e-11 || sBM < 1e-11 {
			break
		}
	}

	fmt.Printf("%.6f\n", ans)
}