• 杭电OJ第4015题 Mario and Mushrooms


      杭电OJ第4015题,Mario and Mushrooms题目链接)。

    Mario and Mushrooms

    Problem Description

    Mario usually relaxes himself by walking along the shady track near the Mushroom Kingdom. The evil King Koopa noticed that and placed a lot of mushroom on the road. There are two types of mushrooms, max mushrooms and bad mushrooms. The bad mushrooms will decrease Mario's HP by m points, on the other hand, max mushrooms will increase Mario's HP by one point. The mushrooms are randomly placed on the track and Mario will receive them one by one. Once Mario's HP becomes zero or below after he received a mushroom, he will die.
    Notice that Mario begins with HP zero, so if the first mushroom is bad, Mario will die immediately. Fortunately, if Mario receives all the mushrooms, he will be alive with HP 1. In the other words, if there are k bad mushrooms on the way, there will also be m*k+1 max mushrooms.
    Princess Peach wants to know the possibility for Mario staying alive. Please help her to calculate it out.

    Input

    There are several test cases. The first line contains only one integer T, denoting the number of test cases.
    For each test case, there is only one line including two integers: m and k, denoting the amount of points of HP the Mario will decrease if he receives a bad mushroom, and the number of bad mushrooms on the track. (1 ≤ m ≤ 1000, 1 ≤ k ≤ 1000)

    Output

    For each test case, output only real number denoting the possibility that Mario will survive if he receives all the randomly placed mushrooms one by one. The answer should be rounded to eight digits after the decimal point.

    Sample Input

    2
    1 1
    60 80

    Sample Output

    Case #1: 0.33333333
    Case #2: 0.00020488

    Source

    The 36th ACM/ICPC Asia Regional Shanghai Site —— Warmup

      解题思路:这种题目推公式要推很久的。不如直接算出小数据,找规律,答案一下子就出来了。C语言代码如下:

    #include <stdio.h>
    #include <stdlib.h>
    
    typedef int COUNT;
    
    int main (void)
    {
        COUNT i;
        int n;
        int dec, bad;
        double probability;
        scanf( "%d", &n );
        for ( i = 1 ; i <= n ; i ++ )
        {
            scanf( "%d%d", &dec, &bad );
            probability = (double)1.0 / (double)( bad + dec * bad + 1 );
            printf( "Case #%d: %.8f\n", i, probability );
        }
        return EXIT_SUCCESS;
    }
  • 相关阅读:
    PHP的注释规范
    IP地址与,域名,DNS服务器,端口号的联系与概念
    转: CentOS上安装LAMP之第一步:Apache环境及安装过程报错解决方案(纯净系统环境)
    转:VMware中CentOS配置静态IP进行网络访问(NAT方式和桥接模式)
    虚拟主机详细的配置
    PHP操作MySQL
    【优化】EXPLAIN--type
    数据库范式
    【优化】碎片OPTIMIZE
    【原理】原理与优化(二)
  • 原文地址:https://www.cnblogs.com/yejianfei/p/2697838.html
Copyright © 2020-2023  润新知