Two soup containers, A and B, both start with n mL.
On each turn, one serving pattern is chosen randomly (all equally likely):
| Operation | Amount Taken from A | Amount Taken from B |
|---|---|---|
| 1 | 100 mL | 0 mL |
| 2 | 75 mL | 25 mL |
| 3 | 50 mL | 50 mL |
| 4 | 25 mL | 75 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.
Input: n = 40
Output: 0.59375
Explanation:
Depending on which operations happen, A may empty first or both may empty together with certain probabilities.
Input: n = 80
Output: 0.70500
Explanation:
As initial soup increases, chances shift slightly in favor of simultaneous depletion or delayed consumption.
Accepted:
Submission: