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

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

题目大意:孤岛上有T只老虎,D只鹿,1个人(你).每天会有两种动物相遇,其中:

1.老虎和人相遇,人必败;

2.老虎和鹿相遇,鹿必败;

3.老虎和老虎相遇,双方都得死;

4.鹿和鹿相遇,什么也不发生;

5.人和鹿相遇,人必定不败,鹿未必;

最后让你求人活下来的概率.

我们会发现这样一个事实,人的威胁就是老虎.所以,如果到最后,还有老虎没死,那么人必死.

所以如果有奇数只老虎,人必败,输出0;若没有老虎,显然人肯定能存活,输出1;

主要是关注,有2k只老虎(k>0)时,人的存活情况.显然,人存活的情况,那2k只老虎都成对死亡.

由于我们可以直接忽略鹿的存在(不影响结果),所以在第一天,选取两只动物总共的方案数为(2k+1)2k,其中,没有人的方案数为2k(2k-1),则第一天,人存活的概率为后者除以前者,也就是(2k-1)/(2k+1).

由于最多总共有k天,则第i(1<i<=k)天时,人依然存活的概率是第i-1天的概率乘以(2(k-i+1)-1)/(2(k-i+1)+1).最后输出就好了.

 #include<cstdio>
 #include<cstring>
 #include<algorithm>
 #include<cmath>
 using namespace std;
 int T,D;
 int main(){
     int Tt; scanf("%d",&Tt);
     ; Ts<=Tt; Ts++){
         scanf("%d%d",&T,&D);
         ;
         ) ans=; else
         ) ans=; else
         ; T-=) ans*=()/();
         printf("Case %d: %.10lf\n",Ts,ans);
     }
     ;
 }

[LightOJ 1265] Island of Survival的更多相关文章

  1. LightOJ - 1265 Island of Survival —— 概率

    题目链接:https://vjudge.net/problem/LightOJ-1265 1265 - Island of Survival    PDF (English) Statistics F ...

  2. LightOj 1265 - Island of Survival(概率)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1265 题目大意:有一个生存游戏,里面t只老虎,d只鹿,还有一个人,每天都要有两个生物碰 ...

  3. LightOJ - 1265 Island of Survival (概率dp)

    You are in a reality show, and the show is way too real that they threw into an island. Only two kin ...

  4. LightOJ.1265.Island of Survival(概率)

    题目链接...我找不着了 \(Description\) 岛上有t只老虎,1个人,d只鹿.每天随机有两个动物见面 1.老虎和老虎碰面,两只老虎就会同归于尽: 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉 ...

  5. LightOJ - 1265 Island of Survival 期望

    题目大意:有一个生存游戏,里面t仅仅老虎,d仅仅鹿,另一个人,每天都要有两个生物碰面,如今有下面规则 1.老虎和老虎碰面.两仅仅老虎就会同归于尽 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方 3.人 ...

  6. LightOJ 1065 Island of Survival (概率DP?)

    题意:有 t 只老虎,d只鹿,还有一个人,每天都要有两个生物碰面,1.老虎和老虎碰面,两只老虎就会同归于尽 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方 3.人和鹿碰面,人可以选择杀或者不杀该鹿4. ...

  7. LightOj:1265-Island of Survival

    Island of Survival Time Limit: 2 second(s) Memory Limit: 32 MB Program Description You are in a real ...

  8. Island of Survival 概率

    #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> ...

  9. LightOj_1265 Island of Survival

    题目链接 题意: 在孤岛生存, 孤岛上有t头老虎,d头鹿, 每天会出现随机出现两只生物(包括你自己), 如果出现了一只老虎,那么你将被吃掉, 如果两只老虎, 则两只老虎会同归于尽,其他情况你都将生存下 ...

随机推荐

  1. DPDK 网卡绑定和解绑

    参考: DPDK网卡绑定和解绑 DPDK的安装与绑定网卡 DPDK 网卡绑定和解绑 注意: 建议不要使用本文的eth0网卡绑定dpdk驱动. 1.进入DPDK目录: $ cd dpdk/tools/ ...

  2. 总结Javascript中数组各种去重的方法

    相信大家都知道网上关于Javascript中数组去重的方法很多,这篇文章给大家总结Javascript中数组各种去重的方法,相信本文对大家学习和使用Javascript具有一定的参考借鉴价值,有需要的 ...

  3. PHP变量的值类型和引用类型

    PHP 变量在内存中保存的并不直接是值的内容而是值的地址.比如: $a = 1; 从表面上看起来似乎是 $a 直接存储了 1 这个值.但是实际情况是,PHP 解释器创建了变量 $a , 将值 1 存入 ...

  4. PHP 冒泡排序(Bubble Sort)

    冒泡排序指的是依次比较相邻的两个数,然后根据大小做出排序,直至最后两位数.因为在排序的 过程中总是小数放前面,大数放后面,和气泡上升有点类似,所以又称作冒泡排序. 下面通过一个实例看一下如何实现冒泡排 ...

  5. Adobe photoshop CS5(32位and64位)破解补丁

    转载自:http://www.wusiwei.com 网上有很多photoshop cs5的永久序列号,但这个在2年前还能有用,现在一般都不行,序列号给你验证过了,然后过几秒钟还是会弹出要你输入序列号 ...

  6. "ProgrammerHome"项目笔记

    系统目的: 1.技术练习:把平时不用的,重要技术栈,在此项目中打磨(java.python.算法.系统构架) 2.新技术(工具)应用:有些平时想做,想实现的技术,可以在这里实现.而且以微服务的方式,轻 ...

  7. python 启动新进程执行脚本

    import subprocess p_restart=subprocess.Popen(['/bin/sh','/etc/init.d/xxx_service','reboot'])

  8. NET Core 指令启动

    ASP.NET Core 是新一代的 ASP.NET,早期称为 ASP.NET vNext,并且在推出初期命名为ASP.NET 5,但随着 .NET Core 的成熟,以及 ASP.NET 5的命名会 ...

  9. 《剑指offer》第六十七题(把字符串转换成整数)

    // 面试题67:把字符串转换成整数 // 题目:请你写一个函数StrToInt,实现把字符串转换成整数这个功能.当然,不 // 能使用atoi或者其他类似的库函数. #include <ios ...

  10. Linux-Ubuntu16.0.4相关命令

    1.更新软件源 sudo apt-get update 2.shell命令 基本格式:命令  [-选项] [-命令参数] ls #查看当前文件夹下的文件 ls -l XXXX #查看XXXX文件夹下的 ...