• LightOJ


    题目链接:https://vjudge.net/problem/LightOJ-1265

    1265 - Island of Survival
    Time Limit: 2 second(s) Memory Limit: 32 MB

    You are in a reality show, and the show is way too real that they threw into an island. Only two kinds of animals are in the island, the tigers and the deer. Though unfortunate but the truth is that, each day exactly two animals meet each other. So, the outcomes are one of the following

    a)      If you and a tiger meet, the tiger will surely kill you.

    b)      If a tiger and a deer meet, the tiger will eat the deer.

    c)      If two deer meet, nothing happens.

    d)      If you meet a deer, you may or may not kill the deer (depends on you).

    e)      If two tigers meet, they will fight each other till death. So, both will be killed.

    If in some day you are sure that you will not be killed, you leave the island immediately and thus win the reality show. And you can assume that two animals in each day are chosen uniformly at random from the set of living creatures in the island (including you).

    Now you want to find the expected probability of you winning the game. Since in outcome (d), you can make your own decision, you want to maximize the probability.

    Input

    Input starts with an integer T (≤ 200), denoting the number of test cases.

    Each case starts with a line containing two integers t (0 ≤ t ≤ 1000) and d (0 ≤ d ≤ 1000) where t denotes the number of tigers and d denotes the number of deer.

    Output

    For each case, print the case number and the expected probability. Errors less than 10-6 will be ignored.

    Sample Input

    Output for Sample Input

    4

    0 0

    1 7

    2 0

    0 10

    Case 1: 1

    Case 2: 0

    Case 3: 0.3333333333

    Case 4: 1

    题意:

    一座岛上有t只老虎、d只鹿和1个人。枚举随机抽取两只动物(包括人)碰面。如果鹿遇鹿则无事;如果鹿遇虎,则鹿死;如果虎遇虎,则都死;如果人遇鹿,则鹿可能死也可能不死;如果人遇虎,则人死。问人生存的概率是多少?

    题解:

    1.可知,人能否存活只与老虎有关。

    2.当老虎的数量为奇数时,人生存的概率为0。因为老虎是成对成对死的,那么最后必定能剩下一只老虎把人吃掉。

    3.当老虎的数量为偶数时,只有在选中人与虎之前,老虎成对成对地死,人才有可能存活。

    4.概率 P = C[t][2]/C[t+1][2]*C[t-2][2]/C[t-1][2]……*C[2][2]/C[3][2] = (t-1)/(t+1)*(t-2)/(t-1)*…… * 2/3 。

    解释:由于鹿对人的存活没有影响,故可忽略其存在。C[t][2]/C[t+1][2]:从t只虎和1个人中选2个出来,2个都是老虎的概率。老虎一直递减、连乘是把老虎都解决完。

    代码如下:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <vector>
     6 #include <cmath>
     7 #include <queue>
     8 #include <stack>
     9 #include <map>
    10 #include <string>
    11 #include <set>
    12 using namespace std;
    13 typedef long long LL;
    14 const int INF = 2e9;
    15 const LL LNF = 9e18;
    16 const int MOD = 1e9+7;
    17 const int MAXN = 1e5+100;
    18 
    19 double dp[MAXN];
    20 int main()
    21 {
    22     int T, t, d, kase = 0;
    23     scanf("%d", &T);
    24     while(T--)
    25     {
    26         scanf("%d%d", &t,&d);
    27         if(t%2)
    28             printf("Case %d: 0
    ", ++kase);
    29         else
    30         {
    31             double ans = 1.0;
    32             while(t) ans *= 1.0*(t-1)/(t+1),  t -= 2;
    33             printf("Case %d: %.10lf
    ", ++kase, ans);
    34         }
    35     }
    36 }
    View Code
  • 相关阅读:
    K近邻法
    感知机
    统计学习方法概论
    神经网络的学习 Neural Networks learing
    对线性回归、逻辑回归、各种回归的概念学习
    从零开始创建VUE项目
    Java中Log4j.properties配置文件详解
    Java中Log4j的入门实例
    Java中Log4j的基本使用方法说明
    C#与Java的RSA中的X509EncodedKeySpec、PKCS8EncodedKeySpec
  • 原文地址:https://www.cnblogs.com/DOLFAMINGO/p/8444660.html
Copyright © 2020-2023  润新知