题目链接:http://lightoj.com/volume_showproblem.php?problem=1265

题目大意:有一个生存游戏,里面t只老虎,d只鹿,还有一个人,每天都要有两个生物碰面,现在有以下规则 
1.老虎和老虎碰面,两只老虎就会同归于尽 
2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方 
3.人和鹿碰面,人可以选择吃或者不吃该鹿 
4.鹿和鹿碰面,相安无事 
问人存活下来的概率

人生存下来的条件就是不被老虎吃掉,所以只要所有的老虎都同归于尽了,人就可以生存下来了 

如果老虎的数量是奇数,那么人总有一天会被吃掉的 
如果老虎的数量是偶数,那就算一下所有老虎同归于尽的概率,这个概率就是人存活下来的概率了 
鹿可以忽略不计。在时间无限的情况下,老虎没死光的话,鹿总有一天是会被全部吃掉的

当老虎的数量是偶数是:总情况就是在tiger+1(老虎和人)里面选两个碰面C(tiger+1, 2);两只老虎碰面的情况是C(tiger, 2),

所以两只老虎碰面的概率是(tiger-1)/(tiger+1);

#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
using namespace std;
#define N 105
#define met(a, b) memset(a, b, sizeof(a))
#define MOD 110119 typedef long long LL; int main()
{
int T, t = ; scanf("%d", &T); while(T--)
{
int tiger, deer;
scanf("%d %d", &tiger, &deer);
if(tiger == ) ///没有老虎,一定能存活;
printf("Case %d: 1\n", t++);
else if(tiger% == ) ///奇数个老虎,一定不能存活;
printf("Case %d: 0\n", t++);
else
{
double ans = 1.0;
while(tiger)
{
ans *= (tiger-1.0)/(tiger+1.0);
tiger -= ;
}
printf("Case %d: %.6f\n", t++, ans);
}
}
return ;
}

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 (概率dp)

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

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

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

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

  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. Nginx 默认虚拟主机

    一台服务器可以配置多个网站,每个网站都称为一个虚拟主机,默认的虚拟主机可以通过 default_server 来指定:: [root@localhost ~]$ cat /usr/local/ngin ...

  2. Unity Shader 设置纹理采样tex2D过滤方式

    双击红色框区域

  3. map 集合的遍历

    List<Map<String,Object>> autoReplyList= wechatService.queryAutoReplyByOrg(orgId); for(Ma ...

  4. codeblocks编码设置

    注意编码统一,即文件编码和编译时的编码统一即可. codeblock13.12下: 文件编码: setting -> editor ->general setting -> othe ...

  5. 【存储过程】用SQL语句获得一个存储过程返回的表

    定义一个存储过程如下: create proc [dbo].[test1] @id int as select 1 as id,'abc' as name union all select @id a ...

  6. 原生js--http请求

    1.终止请求和超时 终止请求XMLHttpRequest对象提供abort方法,调用该方法时触发abort事件 XHR2提供了timeout属性,当超时发生时触发timeout事件.但浏览器尚不支持自 ...

  7. Python中四种运行其他程序的方式

    原文地址:http://blog.csdn.net/jerry_1126/article/details/46584179 在Python中,可以方便地使用os模块来运行其他脚本或者程序,这样就可以在 ...

  8. Android 冷启动时间优化

    一 下载工具: 1.MaterialColdStart https://github.com/DreaminginCodeZH/MaterialColdStart 2.AndroidSVGScript ...

  9. linux mint 安装 SecureCRT

    最喜欢的ssh工具莫过于SecureCRT了,功能强大,方便易用.最近安装了mint17.1(基于ubuntu),就想安装一个SecureCRT来使用. [此SecureCRT仅作测试使用,不做商业用 ...

  10. import 与 from…import 的区别

    首先你要了解 import 与 from…import 的区别. import 模块:导入一个模块:注:相当于导入的是一个文件夹,是个相对路径. from…import:导入了一个模块中的一个函数:注 ...