LightOJ 1265 Island of Survival【概率】

版权声明:转载什么的好说,附上友链就ojek了,同为咸鱼,一起学习。<br> https://blog.csdn.net/sodacoco/article/details/89045092

参看资料:

https://blog.csdn.net/dllpXFire/article/details/81186064


题目:

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 ddenotes 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

4

0 0

1 7

2 0

0 10

Sample Output

Case 1: 1

Case 2: 0

Case 3: 0.3333333333

Case 4: 1

题目大意: 

       一个森林里面有多只老虎,多只老虎,1个人,每天至少有两个生物碰面:老虎与老虎,都over;老虎与人,人over;老虎与鹿,鹿over;鹿与人,擦肩而过。问最后人活下来的概率。

解题思路:

       该题最后求的结果与天数无关,而与老虎的数目有关;当老虎为奇数时,最后总会剩余一直老虎,人存活的概率为0;当老虎的数目为奇数时,一直选两只老虎虎咬虎,求人最后剩下的概率。是的,和鹿的数目没有关系。

实现代码:

#include<iostream>
#include<cstdio>
using namespace std;

int main(){
    int t,n,m;
    scanf("%d",&t);

    for(int k=1;k<=t;k++){
        scanf("%d%d",&n,&m);
        double ans=1;
        if(n%2==0){
            while(n!=0){
                ans*=(n-1)*1.0/(n+1);
                n-=2;
            }
        }else{
            ans=0;
        }
        printf("Case %d: %lf\n",k,ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sodacoco/article/details/89045092