题目链接:https://vjudge.net/problem/LightOJ-1265

1265 - Island of Survival
Time Limit: 2 second(s) Memory Limit: 32 MB

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

Output for Sample Input

4

0 0

1 7

2 0

0 10

Case 1: 1

Case 2: 0

Case 3: 0.3333333333

Case 4: 1

题意:

一座岛上有t只老虎、d只鹿和1个人。枚举随机抽取两只动物(包括人)碰面。如果鹿遇鹿则无事;如果鹿遇虎,则鹿死;如果虎遇虎,则都死;如果人遇鹿,则鹿可能死也可能不死;如果人遇虎,则人死。问人生存的概率是多少?

题解:

1.可知,人能否存活只与老虎有关。

2.当老虎的数量为奇数时,人生存的概率为0。因为老虎是成对成对死的,那么最后必定能剩下一只老虎把人吃掉。

3.当老虎的数量为偶数时,只有在选中人与虎之前,老虎成对成对地死,人才有可能存活。

4.概率 P = C[t][2]/C[t+1][2]*C[t-2][2]/C[t-1][2]……*C[2][2]/C[3][2] = (t-1)/(t+1)*(t-2)/(t-1)*…… * 2/3 。

解释:由于鹿对人的存活没有影响,故可忽略其存在。C[t][2]/C[t+1][2]:从t只虎和1个人中选2个出来,2个都是老虎的概率。老虎一直递减、连乘是把老虎都解决完。

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e5+; double dp[MAXN];
int main()
{
int T, t, d, kase = ;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &t,&d);
if(t%)
printf("Case %d: 0\n", ++kase);
else
{
double ans = 1.0;
while(t) ans *= 1.0*(t-)/(t+), t -= ;
printf("Case %d: %.10lf\n", ++kase, ans);
}
}
}

LightOJ - 1265 Island of Survival —— 概率的更多相关文章

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

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

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

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

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

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

  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. Island of Survival 概率

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

  8. LightOj:1265-Island of Survival

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

  9. LightOJ - 1265 (概率)

    题意: 1.两只老虎相遇 就互相残杀 2.老虎与鹿相遇 鹿死 3.老虎与人相遇 人死 4.人与鹿相遇     鹿死 5.鹿与鹿相遇     无果 求人活的概率 解析:如果老虎为0  则人活得概率为1 ...

随机推荐

  1. 2016.7.12 去除mybatis-generator生成的class里的注释

    用mybatis-generator自动生成代码会出现很多没必要的注释.     在配置文件里加上: 是否去除所有自动生成的文件的时间戳: 是否去除所有自动生成文件的注释: <commentGe ...

  2. Xcode中的变量模板(variable template)的使用方法

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 假设认为写的不好请多提意见,假设认为不错请多多支持点赞.谢谢! hopy ;) 你可能常常会写一些小的代码片段,里面自然少不了一些关键的变量. ...

  3. void f(int(&amp;p)[3]){} 和void f(int(*p)[3]){}的差别

    #include<iostream> using namespace std; void f(int(&p)[3]){          cout<<p[0]<& ...

  4. java使用Runtime.exec()运行windwos dos或linux shell命令

    使用Runtime.exec()运行windwos dos或linux shell命令,按实际情况具体测试     实例代码: package com.bookoo.test.command; imp ...

  5. 转 FreeBSD 安装JDK

    cd /usr/ports/java/openjdk6make install clean 默认什么都不用选,因为我们配置的是运行环境, 中间编译过程好久... 偷懒的干脆就直接安装/usr/port ...

  6. Linux下MySQL定时按日期备份数据

    一.使用mysql内置命令 mysqldump Usage: mysqldump [OPTIONS] database [tables] mysqldump [OPTIONS] --databases ...

  7. Android有关surfaceView又一次创建的问题。

    近期在做一个Android视频播放器的项目.遇到一个问题,就是锁屏之后.surfaceview就会被销毁掉,然后就会出现各种错误.到csdn论坛去发帖提问,各种所谓的大神都说,解锁屏在又一次创建一个, ...

  8. Selenium学习(三)Selenium总是崩溃的解决办法

    在使用selenium打开浏览器总是崩溃,最近查资料获得可行的解决办法: import sys from selenium import webdriver p = __import__('selen ...

  9. python学习(八)阶段性总结

    这里学习了python的一点点基础然后来总结一下 python是一个强类型的语言 数字: 数字的类型大概有:整数.浮点数.复数.固定精度的十进制数.带分子和分母的有理数 数字与字符串之间不能直接相加, ...

  10. VIM中保存编辑的只读文件

    如何在VIM中保存编辑的只读文件 你是否会和我一样经常碰到这样的情景:在VIM中编辑了一个系统配置文件,当需要保存时才发现当前的用户对该文件没有写入的权限.如果已 经做了很多修改,放弃保存的确很懊恼, ...