Island of Survival

Time Limit: 2 second(s) Memory Limit: 32 MB

Program Description

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

4

0 0

1 7

2 0

0 10

Output for Sample Input

Case 1: 1

Case 2: 0

Case 3: 0.3333333333

Case 4: 1


解题心得:

  1. 很有意思的一道题,如果很天真的跟着题意走,那就直接入坑了。其实,这里面的鹿根本没啥用啊

    • 从思想上来理解,人遇到了鹿对人没影响,老虎遇到了鹿对老虎没影响,最后的概率只跟老虎和人有关系,所以在遇到鹿的情况直接忽略就当什么也没发生。
    • 从数学上来理解,最后列出方程会发现,关于鹿的部分可以直接约分约掉,也是对于最后答案没有影响的。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
double dp[maxn]; double get_pro(double x,double y)
{
double x1 = y*(y-1.0);
double x2 = x*(x-1.0);
double ans = x2/x1;
return ans;
} int main()
{
int T,cas = 1;
scanf("%d",&T);
while(T--)
{
memset(dp,0,sizeof(dp));
int t,d;
scanf("%d%d",&t,&d);
if(t%2 != 0)//如果老虎是单数,那么人必死
{
printf("Case %d: %.8f\n",cas++,0);
continue;
}
for(int i=0;i<=t;i+=2)
{
if(i == 0)
{
dp[i] = 1.0;
continue;
}
dp[i] = get_pro(i,i+1);
if(i >= 2)
dp[i] *= dp[i-2];
}
printf("Case %d: %.8f\n",cas++,dp[t]);
}
}

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

    Island of Survival You are in a reality show, and the show is way too real that they threw into an i ...

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

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

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

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

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

  8. 51Nod:1265 四点共面

    计算几何 修改隐藏话题 1265 四点共面  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出三维空间上的四个点(点与点的位置均不相同),判断这4个点 ...

  9. LightOj:1030-Discovering Gold(期望dp模板)

    传送门:http://www.lightoj.com/volume_showproblem.php?problem=1030 Discovering Gold Time Limit: 2 second ...

随机推荐

  1. pytorch 0.3 win7 安装

    pytorch 0.3 win7 安装 参考这个文章:https://github.com/peterjc123/pytorch-scripts 首先安装 conda 这个链接下载: python 3 ...

  2. 日历插件:Bootstrap的datetimepicker插件

    注意:可以选择性引入 bootstrap.min.css和bootstrap.min.js,引入样式更好控制 option选项 0-hour 1-day 2-month 3-year 4-all ye ...

  3. Flat UI theme--扁平化的UI

    项目地址:点击打开 支持版本: jQuery Mobile 1.3.2 使用很简单,前提是你的前端是在jquery-mobile的基础上开发的,然后导入相应的css文件.img文件和js文件即可. 案 ...

  4. 老生常谈Java虚拟机垃圾回收机制(必看篇)

    二.垃圾收集 垃圾收集主要是针对堆和方法区进行. 程序计数器.虚拟机栈和本地方法栈这三个区域属于线程私有的,只存在于线程的生命周期内,线程结束之后也会消失,因此不需要对这三个区域进行垃圾回收. 判断一 ...

  5. 如何检查linux 下是否安装java(jdk)环境

    大家可通过下面五条命令来查看linux 系统是否安装了java 环境 1.java -version 2.which java 3.rpm -qa |grep java 4.echo $PATH 5. ...

  6. java初探之初始化

    首先明确,变量初始化是在任何方法(包括构造器)被调用之前进行的. 1.实例变量的初始化 实例变量只有当它所属的类实例化后才会存在,构造器被执行就意味着对象就被创建. 1.1.指定初始化. class ...

  7. 《超实用的Node.js代码段》连载一:获取Buffer对象字节长度

    我们知道Node.js框架下的Buffer对象能够对二进制数据提供很好的支持,那么获取一个Buffer对象真实的字节长度则是必须要用到的功能了.Node.js框架为开发人员提供了一个Buffer.by ...

  8. java-web项目:用servlet监听器实现显示在线人数

    1.创建一个监听器 package com.listener; import javax.servlet.ServletContext; import javax.servlet.http.HttpS ...

  9. tomcat配置https 和 http强制跳转https

    https是http+ssl的可进行加密传输,身份认证的网络协议,防止数据在传输过程中被窃取.因此,https将得到越来越广泛的应用,下面是如何配置tomcat服务器让http自动转到https的步骤 ...

  10. log4cpp安装使用

    1. 主页:http://log4cpp.sourceforge.net“Log4cpp is library of C++ classes for flexible logging to files ...