Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Soup Servings

XPChallenge Points: 20
levelLevel: Medium

Two soup containers, A and B, both start with n mL.
On each turn, one serving pattern is chosen randomly (all equally likely):

OperationAmount Taken from AAmount Taken from B
1100 mL0 mL
275 mL25 mL
350 mL50 mL
425 mL75 mL

If the requested amount is more than what remains, the soup is reduced to 0.

The process ends when either A or B becomes empty.

Return:
Probability(Soup A empties first) +
½ × Probability(both soups empty on the same turn)

Your result should be accurate within 1e-5.

Example 1:

Input: n = 40

Output: 0.59375

Explanation:

Depending on which operations happen, A may empty first or both may empty together with certain probabilities.

Example 2:

Input: n = 80

Output: 0.70500

Explanation:

As initial soup increases, chances shift slightly in favor of simultaneous depletion or delayed consumption.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result