F - God of Gamblers西安区域赛

版权声明:如需转载,请注明出处: https://blog.csdn.net/qq_38701476/article/details/83153024

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 3fi
he will win 2k RMB back fiotherwise 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

  • 解题思路:直接输出n/(m+n)即可
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool SUBMIT = 1;
int main()
{
	double n,m;
	while(~scanf("%lf %lf",&n,&m)){
	//cout<<n<<m<<endl;
	printf("%.5lf\n",n/(n+m));
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_38701476/article/details/83153024
今日推荐