题目链接: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. 2017.2.13 开涛shiro教程-第十二章-与Spring集成(一)配置文件详解

    原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. 第十二章-与Spring集成(一)配置文件详解 1.pom.xml ...

  2. 社区之星礼品开箱——感谢CSDN

    前言 尽管已经看过国内外无数的开箱.评測视频,也看过无数国内社区的各种玩具.电子产品.摄影的分享贴.自己却从未写过--摄影水平有限以及懒-- 昨天看到上图的文章,看到最后都说了应该晒晒照片.写写博客, ...

  3. Android 基于Retrofit+Rxjava搭建的简单易用的网络架构

    装逼開始之前,为大家推荐两篇文章,用来更好的学习Retrofit和Rxjava. 在这里我们要感谢互联网装逼行业勇于献身,甘于奉献的的大婶们. 我仅代表个人,给您们跪舔了. Retrofit:Retr ...

  4. C/C++内存管理详解(转)

    内存分配方式 简介 在C++中,内存分成5个区,他们分别是堆.栈.自由存储区.全局/静态存储区和常量存储区. 栈:在执行函数时,函数内局部变量的存储单元都可以在栈上创建,函数执行结束时这些存储单元自动 ...

  5. 生成二维码 加密解密类 TABLE转换成实体、TABLE转换成实体集合(可转换成对象和值类型) COOKIE帮助类 数据类型转换 截取字符串 根据IP获取地点 生成随机字符 UNIX时间转换为DATETIME\DATETIME转换为UNIXTIME 是否包含中文 生成秘钥方式之一 计算某一年 某一周 的起始时间和结束时间

    生成二维码 /// <summary>/// 生成二维码/// </summary>public static class QRcodeUtils{private static ...

  6. python实现区块链代码

    如果你明白了原理其实挺简单的. 加密算法是python自带的 需要导入hashlib import hashlib as hash sha = hasher.sha256() sha.update(' ...

  7. 贷前系统ElasticSearch实践总结

    贷前系统负责从进件到放款前所有业务流程的实现,其中涉及一些数据量较大.条件多样且复杂的综合查询,引入ElasticSearch主要是为了提高查询效率,并希望基于ElasticSearch快速实现一个简 ...

  8. 小明同学喜欢体育锻炼,他常常去操场上跑步。跑道是一个圆形,在本题中,我们认为跑道是一个半径为R的圆形,设圆心的坐标原点(0,0)。小明跑步的起点坐标为(R,0),他沿着圆形跑道跑步,而且一直沿着一个方向跑步。回到家后,他查看了自己的计步器,计步器显示他跑步的总路程为L。小明想知道自己结束跑步时的坐标,但是他忘记自己是沿着顺时针方向还是逆时针方向跑的了。他想知道在这两种情况下的答案分别是多少。

    include "stdafx.h" #include<iostream> #include<vector> #include<string> ...

  9. Jquery EasyUI弹出窗体

    $("#btnCreate").click(function () { $("#modalwindow").html("<iframe widt ...

  10. MongoDB安装配置(Windows)

    官网下载:https://www.mongodb.com/ 百度经验:https://jingyan.baidu.com/article/d5c4b52bef7268da560dc5f8.html 官 ...