Sicily 1839. Stone Game

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.000000

0.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;
}                                 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值