1598.Dice

Time Limit: 1s Memory Limit: 256MB

The dice game is very common in movies. Briefly, the rule is that you need to bet on your choice, and the probability of winning is one-half. If you win, your money will get doubled, otherwise you will lose your money in this round.

One day, Tom came up with a brilliant strategy to make sure he wouldn't lose much money.

The steps of the strategy are described as following:

  1. He would play n rounds of the dice game at most.
  2. Start betting with 1 dollar in the first round, and double the bet in the next round.
  3. If he won the game in a round, he would not take part in the following.

Now Tom wants to know the probability of his winning the money using this strategy.

Input Format(From the terminal/stdin)

The first line contains a number $t(t≤20)$ indicating that there are t test cases.
The next t lines contain a number $n(n≤20)$ each, indicating that the maximum round Tom would play.

Output Format(To the terminal/stdout)

Please output the probability that Tom will make money.(Reserve 4 digits after the decimal point)

Sample Input

Copy
2
1
2
 \n
 \n
 \n

Sample Output

Copy
0.5000
0.7500
      \n
      \n

Hints

Please use double instead of float In the first test case, $n$ equals to $1$.
The probability of wining and losing are equal, so the probability of winning at the first time is $0.5000$.
In the second test case, $n$ equals to $2$.The probability of wining and losing are equal, so the probability of winning at the first time is $0.5000$. When lose the game at the first time, the probability of winning at the second time is $0.5000$. Therefore the probability that Tom will make money equal to $0.5000 + 0.5000 \times 0.5000 = 0.7500$.

Source: 2019 HNU新生赛

Submit

请先 登录

© 2025 FAQs