Facebook Hacker Cup 2017 Qualifying Round
"Okay, Wizard, cast your spell!"
But which of your many spells to cast? In the ever-popular role-playing game Dungeons & Dragons, or D&D, you determine a spell's damage by rolling polyhedral dice with XdY
means "roll a XdY+Z
or XdY-Z
respectively.
For example, if you roll 2d4+1
, you'll end up with a result between 1d6-3
, your result will be between
In D&D, wizards are powerful but flimsy spellcasters. As a wizard fighting a zombie, your best strategy is to maximize the chance that you can kill the zombie with a single spell before it has a chance to retaliate. What spell should you cast?
Input Specification
Input begins with an integer
Output Specification
For each zombie, print a line containing the probability of defeating the zombie if you select your spell optimally.
Absolute and relative errors of up to
Constraints
Additionally, the following constraints will hold for each spell:
Sample Input
5
2 2
2d4 1d8
10 2
10d6-10 1d6+1
8 3
1d4+4 2d4 3d4-4
40 3
10d4 5d8 2d20
10 4
1d10 1d10+1 1d10+2 1d10+3
Sample Output
Case #1: 1.000000
Case #2: 0.998520
Case #3: 0.250000
Case #4: 0.002500
Case #5: 0.400000
Explanation of Sample
In the first case, you can guarantee a kill with the first spell, which must always do at least
In the third case, your first spell is the best. If you roll a
Comments