OI Problems   关于

#m0qtk3. A game with probability

时间限制:100 ms       空间限制:1.5 GiB       标签: 数学 概率期望 递推 SPOJ 缺题解 

算法难度等级:0       思维难度等级:0       实现难度等级:0


本题来源于:SPOJ KPGAME - A game with probability

  • 简体中文
  • English

题目描述

Alice 和 Bob 在玩一个游戏。

nn 个石子在这里,Alice 和 Bob 轮流投掷硬币,如果正面朝上,则从 nn 个石子中取出一个石子,否则不做任何事。取到最后一颗石子的人胜利。Alice 在投掷硬币时有 pp 的概率投掷出他想投的一面,Bob 有 qq 的概率投掷出他相投的一面。

现在 Alice 先手投掷硬币,假设他们都想赢得游戏,问你 Alice 胜利的概率为多少。

输入格式

Input starts with a line containing one integer TT - a number of test cases (1T501\leq T\leq 50). Then TT test cases follow. Each of them is one line with three numbers NN, PP, and QQ separated with a space (1N999999991\leq N\leq 99999999, 0.5P, Q0.999999990.5\leq P,\ Q\leq 0.99999999). PP and QQ have not more than 88 digits after decimal point.

输出格式

For each test case output one line with a probability that Alice will win the game. Your answer must be precise up to 10610^{-6}.

样例输入输出

1
1 0.5 0.5
0.666666667

Alice and Bob play the following game. First, they collect NN small stones and put them together in one pile. After that, they throw a coin one by one. Alice starts first. If a player throws heads then he takes exactly one stone from the pile. In case of tails he don't do anything. The one who takes the last stone wins. For each player, his skill of throwing a coin is known (to everyone, including himself and his opponent). More precisely, if Alice wants to throw some specific side of the coin, she always succeeds with probability PP. The same probability for Bob is QQ.

You are to find probability that Alice will win the game if both guys play optimally.

Input

Input starts with a line containing one integer TT - a number of test cases (1T501\leq T\leq 50). Then TT test cases follow. Each of them is one line with three numbers NN, PP, and QQ separated with a space (1N999999991\leq N\leq 99999999, 0.5P, Q0.999999990.5\leq P,\ Q\leq 0.99999999). PP and QQ have not more than 88 digits after decimal point.

Output

For each test case output one line with a probability that Alice will win the game. Your answer must be precise up to 10610^{-6}.

Example

1
1 0.5 0.5
0.666666667