1839. Stone Game
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
Dennis and Joyce love to collect stones and play games with them. Up till now they have collected Na white stones and Nb black stones, and they are going to play a new game. The rules of the game is as follows:
(1). All the stones are put into a pocket initially, so that each stone has equal possibility to be picked up, and each time a stone is picked up randomly.
(2). The two players take turns to pick up a stone, if the stone is black, the current player should put it back to the pocket; otherwise the player could keep the stone.
(3). Whoever picks up the last white stone wins the game.
Now they haven’t decided who plays first. To make a better decision, Dennis have asked you, an excellent programmer, to calculate the winning possibility for the first player. Since they are going to start playing soon, you must finish the job as quickly as possible, Come on!
Input
The first line is a single number n, the number of test cases followed. In the next n lines, each line contains two non-negative integers, Na and Nb, (0<=Na, Nb<=64).
Output
For each test case, output a real number indicating the possibility for the first player to win. The answer should be rounded to 6 digits after the decimal point. No extra spaces are allowed.
Sample Input
3 1 0 0 1 3 10
Sample Output
1.000000 0.0000000.500282
// Problem#: 1839 // Submission#: 3271536 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/ // All Copyright reserved by Informatic Lab of Sun Yat-sen University #include <stdio.h> int main() { int caseNum; scanf("%d", &caseNum); while (caseNum--) { int na, nb; scanf("%d%d", &na, &nb); double win[70]; win[0] = 0; for (double i = 1; i <= na; i++) { win[(int)i] = (i * (1 - win[(int)i - 1]) + nb) / (i + 2 * nb); } printf("%lf\n", win[na]); } //getchar(); //getchar(); return 0; }