LightOJ 1265---Island of Survival (概率)

题意:

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

  1. If you and a tiger meet, the tiger will surely kill you.
  2. If a tiger and a deer meet, the tiger will eat the deer.
  3. If two deer meet, nothing happens.
  4. If you meet a deer, you may or may not kill the deer (depends on you).
  5. 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

4

0 0

1 7

2 0

0 10

Sample Output

Case 1: 1

Case 2: 0

Case 3: 0.3333333333

Case 4: 1

思路:虽然这个题不难。但是没有想到,因为鹿要么最后被人吃,要么被虎吃,所以对结果是没有影响的,所以可以直接不考虑,

只需要对虎和人进行考虑,虎为0,人一定存活

虎为奇数,人一定死亡,

就在虎为非0偶数时,对人和虎进行考虑,每次都是选出两只虎,人才能存活,所以就从t只虎和1个人里面,一直选到两只虎的概率,一直到虎全部死亡。。。

(虽然不是难题,思维性也不是特别强,但是忽略鹿这一招,确实是没有想到的,还是写一下,记录一下吧)

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long LL;
#define N 100005
#define INF 0x3f3f3f3f

double z,zz;

int main()
{
    int T, n,m, cas=1;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%d%d", &n,&m);
        if(n==0) printf("Case %d: 1\n", cas++);
        else if(n%2==1) printf("Case %d: 0\n", cas++);
        else {
            printf("Case %d: ", cas++);
            z=1;
        while(n)
        {
            z*=(n-1)*1.0/(n+1);
            n-=2;
        }
                printf("%.10f\n",z);
        }
    }
    return 0 ;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值