[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 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的更多相关文章
- LightOJ - 1265 Island of Survival —— 概率
题目链接:https://vjudge.net/problem/LightOJ-1265 1265 - Island of Survival PDF (English) Statistics F ...
- LightOj 1265 - Island of Survival(概率)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1265 题目大意:有一个生存游戏,里面t只老虎,d只鹿,还有一个人,每天都要有两个生物碰 ...
- 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 ...
- LightOJ.1265.Island of Survival(概率)
题目链接...我找不着了 \(Description\) 岛上有t只老虎,1个人,d只鹿.每天随机有两个动物见面 1.老虎和老虎碰面,两只老虎就会同归于尽: 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉 ...
- LightOJ - 1265 Island of Survival 期望
题目大意:有一个生存游戏,里面t仅仅老虎,d仅仅鹿,另一个人,每天都要有两个生物碰面,如今有下面规则 1.老虎和老虎碰面.两仅仅老虎就会同归于尽 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方 3.人 ...
- LightOJ 1065 Island of Survival (概率DP?)
题意:有 t 只老虎,d只鹿,还有一个人,每天都要有两个生物碰面,1.老虎和老虎碰面,两只老虎就会同归于尽 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方 3.人和鹿碰面,人可以选择杀或者不杀该鹿4. ...
- LightOj:1265-Island of Survival
Island of Survival Time Limit: 2 second(s) Memory Limit: 32 MB Program Description You are in a real ...
- Island of Survival 概率
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> ...
- LightOj_1265 Island of Survival
题目链接 题意: 在孤岛生存, 孤岛上有t头老虎,d头鹿, 每天会出现随机出现两只生物(包括你自己), 如果出现了一只老虎,那么你将被吃掉, 如果两只老虎, 则两只老虎会同归于尽,其他情况你都将生存下 ...
随机推荐
- RN 上传文件到以及上传文件到七牛云(初步)
本文将介绍: 如何使用原生 Javascript 上传文件 如何使用七牛云 SDK 上传文件到七牛云 在 App 中文件上传是一个非常重要的需求,但是翻遍 React Naitve 的官方文档没有发现 ...
- Java中String型与Date型数据的互相转换
/** * Date类型转为指定格式的String类型 * * @param source * @param pattern * @return */ public static String Dat ...
- Jenkins--Credentials添加证书从git上拉代码
直接上图:
- eclipse打开失败
以前eclipse运行好好的,某一次运行启动不了,一直图标那里转圈,不能启动, 运行eclipsec.exe后,查看发现出现以下错误 SLF4J: Class path contains multip ...
- 《剑指offer》第五十五题(二叉树的深度)
// 面试题55(一):二叉树的深度 // 题目:输入一棵二叉树的根结点,求该树的深度.从根结点到叶结点依次经过的 // 结点(含根.叶结点)形成树的一条路径,最长路径的长度为树的深度. //如果左右 ...
- django生成迁移文件
1.创建虚拟环境 在终端上输入创建python3的虚拟环境 mkvirtualenv -p python3 虚拟环境的名字 安装django和pymysql 2.创建项目创建工程的命令: django ...
- docker下debian镜像开启ssh, 允许root用密码登录
用的官方python镜像做开发, 暴露端口, 用pycharm ssh进去开发. 忽然发现本来ssh能连上, 但是更了新的python镜像连不上了. 有折腾了一下, 连上了. 主要是python官网镜 ...
- MySQL命令行的备份与还原
备份的语法; mysqldump -uroot -p shop> 数据库路径 还原的语法: mysql -uroot -p 具体数据库(shop0609)< 数据库路径
- Windows的空格预览神器 | QuickLook
用惯了Mac,发现空格预览真的能极大的提升效率和手感. QuickLook,Windows版的空格预览神器,效果差一些,速度有点慢,勉强用吧.
- Django使用admin管理后台管理数据库表
1.在admin.py文件中注册需要创建的表,例: from .models import * # Register your models here. admin.site.register(Use ...