LightOJ 1265 Island of Survival【概率】

参看资料:

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值