luogu#P5249. [LnOI2019] 加特林轮盘赌

[LnOI2019] 加特林轮盘赌

Background

Gatling roulette is a wellness game.

Problem Description

Unlike gambling games with pistols such as Russian roulette, the game tool in Gatling roulette is a Gatling gun.

The rules of Gatling roulette are simple: bullets are loaded into some parts of the Gatling’s magazine. The players sit at a round table, and take turns aiming the Gatling at their own head and pulling the trigger for one second. Anyone who gets shot is eliminated immediately. The one who lasts to the end is the winner.

We use a Gatling gun with the latest 2019 technology. Its features are no warm-up needed and unlimited bullets. For each person, in each round, the probability of getting shot is exactly the same, P0P_0.

There are nn long-necked deer in each game. Starting from long-necked deer 11, they play in increasing order by number, going around the round table in a loop.

The game may go through multiple cycles, and ends when only the last long-necked deer remains.

Given P0P_0 and nn, find the probability PkP_k that long-necked deer kk will eventually become the only survivor.

If P0=0P_0=0, we consider deer 11 to be the winner.

Input Format

Only one line with three numbers, P0,n,kP_0,n,k.

Output Format

Output a floating-point number PkP_{k}. The error should be less than 10810^{-8}. (Please keep more digits after the decimal point.)

0.5 2 1
0.33333333
0.5 2 2
0.66666667
0.5 3 1
0.23809524
0.5 3 2
0.28571429

Hint

  • For 10%10\% of the testdata, n100n \le 100.
  • For 30%30\% of the testdata, n500n \le 500.
  • For another 20%20\% of the testdata, k=nk = n.
  • For 100%100\% of the testdata, 1kn104,0P011 \le k \le n \le 10^{4}, 0 \le P_0 \le 1.

For all testdata, the time limit is 1000 ms and the memory limit is 256 MB. O2O2 optimization is allowed.

Translated by ChatGPT 5