#P3779. [SDOI2017] 龙与地下城
[SDOI2017] 龙与地下城
Description
Xiao Q is a student who loves studying, but he has recently been obsessed with various games, and Dungeons and Dragons is one of them.
In this game, many situations require rolling dice to generate random numbers, which then determine the character’s fate. Therefore, dice are iconic props in this game.
There are many kinds of dice, such as the -sided die, -sided die, -sided die, -sided die, and -sided die, among which the -sided die is used very often. Of course, with modern technology, a random number generator can replace a real die, so here we assume that a die is a random number generator.
In battles, dice are mainly used to determine whether an attack hits and, if it hits, the damage dealt. For example, suppose we already know the attack will hit; then (i.e., roll -sided dice and sum all numbers shown) is the base damage dealt to the enemy. If the enemy has no defense, this base damage is the actual damage.
It is well known that each face of a die has the same probability. That is, for an -sided die, each number among appears with probability .
More formally, the number shown by this die, , follows a discrete uniform distribution, with the following distribution table:
In addition, it has the following properties:
- The first raw moment (expectation) of is
- The second central moment (variance) of is
Back to the point: Now Xiao Q faces an enemy with health , has no defense, and he can make one guaranteed-hit attack. Obviously, only damage not less than the enemy’s health can defeat the enemy. On the other hand, as a perfectionist, Xiao Q does not want “overkill,” i.e., dealing damage greater than . Therefore, Xiao Q considers it his victory only if he both defeats the enemy and does not have “overkill.”
Because Xiao Q is very cautious, he will run mock battles. Each time, he gives the enemy’s health and the overkill threshold . He wants to know the probability of achieving his own victory under these conditions. Can you help him?
Input Format
The first line contains a positive integer , the number of test cases.
For each test case:
- The first line contains two integers , the number of faces of the die and the number of dice, respectively.
- Then follow lines, each containing two integers , representing the enemy’s health and the overkill threshold .
Output Format
For each test case, output lines. For each query, output a real number. The absolute error must not exceed .
That is, let the output be and the correct answer be . If , the output is considered correct.
1
2 19
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0.000002
0.000038
0.000364
0.002213
0.009605
0.031784
0.083534
0.179642
0.323803
0.500000
Hint
For of the testdata, , , , .
It is guaranteed that there are at most test cases with .
| Test point ID | Note | ||
|---|---|---|---|
| - | |||
Translated by ChatGPT 5
京公网安备 11011102002149号