Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Kitorp and His Wife

By RasheedAbid, DarkknightRHZ · Limits 1s, 512 MB

To encourage Kitorp's promising coding career, his wife Asiar, offers him a prize if he wins (at least) two contest in a row in a three-set contest with his wife and Tourits alternatively: Asiar-Tourits-Asiar or Tourits-Asiar-Tourits, according to Kitorp's choice.

Now, the probability of Kitorp defeating the opponents are given. Find out the probability of Kitorp winning the prize if he optimally chooses the series. Also, you need to find the expected number of wins for the chosen condition.


First line will contain the number of test cases T (0 < T ≤ 100000). The following T lines will have two double numbers t and a, the probability of defeating Tourits and Asiar.


Output the probability of Kitorp winning the prize and the expected number of wins. Error less than 10-6 will be ignored.


0.5 0.5
0.375 1.5



35% Solution Ratio

curly_bracesEarliest, May '18

LU_SchrodenBugFastest, 0.1s

LU_SchrodenBugLightest, 1.7 MB

LU_SchrodenBugShortest, 200B


Login to submit

Toph uses cookies. By continuing you agree to our Cookie Policy.