God of Gamblers

题目
When I was young , my father is a senior gaming enthusiast . One day , we saw a old man in the street . He had a dice and played with other people .Every turn the gambler gives k RMB to the old man and throw the dice . If the point is 1, 2 or 3,he will win 2k RMB back ,otherwise he will get nothing .My father told me , “I can win all his money by the following strategy”.“Each turn , I bet on 1 RMB first . If I lose , I will bet on 2 RMB . If I still lose ,I will bet on 4,8,16,… and so on , until I win . And start to bet on 1 RMB , do the same thing again .”“If I don’t have enough money to bet , I will bet on all my money.”Now the question is , if the dice is even , my father has n RMB , the old man has m RMB , they stop until one of them lose all his money , what’s the probability of my father’s victory .
Input
The input contains multiple test cases.(No more than 20)
In each test case:
The only line contains two numbers n, m. (0 ≤ n, m ≤ 2000000), indicate my father’s money and
the old man’s . We guarantee max(n, m) ≥ 1.
Output
For each test case, print the answer in five decimal .
Sample Input
1 0
3 3
Sample Output
1.00000
0.50000
题目大意
两个人玩骰子游戏,如果骰子的数字是1,2,3那么甲赢2K元,如果不是,那么甲输掉他压得所有钱,并且甲输了的话就会在押,并且这一次押的钱数是上一次的两倍,知道没有钱为止。问甲有多大的概率能赢。
解题思路
显然每一局甲获胜的概率为0.5,而且可以知道,每当甲赢一次,之前所输的钱都会赢回来。
代码如下

#include<iostream>
#include<cstdio>

using namespace std;
int main()
{
 	double n,m;
 	while(~scanf("%lf %lf",&n,&m))
 	{ 
  	printf("%.5lf\n",n/(n+m));
 	}
 	return 0;
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值