2017年ICPC中国大陆区域赛真题(下)B题

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_43735840/article/details/99726046

题目网址点击进入

problem:
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元,每次下注k元,摇色子到1.2.3点我赢2*k元,就是等于赢回下注的k和老人原有的k,若不是这三点则输k元

思路
我们可以换种思想去想,不下注,我手里n,老人手里m,输赢给对方开局约定好的k元即可,我123老人456,每次游戏概率输赢都是50%,但是对于A了的代码有三种,输入相同输出不同,感觉后台数据太水了,但感觉第一种代码比较可靠

代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double n,m;
    while(~scanf("%lf %lf",&n,&m))
    {
        printf("%.5lf\n",n/(n+m));
    }
    return 0;
}

#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LLD;
int main()
{
    LLD n,m;
    while (scanf("%lld %lld",&n,&m)!=EOF)
    {
        if (n>m)
        {
            printf("1.00000\n");
        }else if (n==m)
        {
            printf("0.50000\n");
        }else
        {
            printf("0.00000\n");
        }
    }
    return 0;
}

#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LLD;
int main()
{
    LLD n,m;
    while (scanf("%lld %lld",&n,&m)!=EOF)
    {
        if (m==0&&n!=0)
        {
            printf("1.00000\n");
        }else if (n==0&&m!=0)
        {
            printf("0.00000\n");
        }else
        {
            printf("0.50000\n");
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43735840/article/details/99726046