LightOJ - 1265 Island of Survival —— 概率
题目链接:https://vjudge.net/problem/LightOJ-1265
| 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 —— 概率的更多相关文章
- 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
Island of Survival You are in a reality show, and the show is way too real that they threw into an i ...
- LightOj 1265 - Island of Survival(概率)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1265 题目大意:有一个生存游戏,里面t只老虎,d只鹿,还有一个人,每天都要有两个生物碰 ...
- LightOJ - 1265 Island of Survival 期望
题目大意:有一个生存游戏,里面t仅仅老虎,d仅仅鹿,另一个人,每天都要有两个生物碰面,如今有下面规则 1.老虎和老虎碰面.两仅仅老虎就会同归于尽 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方 3.人 ...
- LightOJ 1065 Island of Survival (概率DP?)
题意:有 t 只老虎,d只鹿,还有一个人,每天都要有两个生物碰面,1.老虎和老虎碰面,两只老虎就会同归于尽 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方 3.人和鹿碰面,人可以选择杀或者不杀该鹿4. ...
- Island of Survival 概率
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> ...
- LightOj:1265-Island of Survival
Island of Survival Time Limit: 2 second(s) Memory Limit: 32 MB Program Description You are in a real ...
- LightOJ - 1265 (概率)
题意: 1.两只老虎相遇 就互相残杀 2.老虎与鹿相遇 鹿死 3.老虎与人相遇 人死 4.人与鹿相遇 鹿死 5.鹿与鹿相遇 无果 求人活的概率 解析:如果老虎为0 则人活得概率为1 ...
随机推荐
- Linux学习之十三-vi和vim编辑器及其快捷键
vi和vim编辑器及其快捷键 1.vi与vim区别 它们都是多模式编辑器,不同的是vim 是vi的升级版本,它不仅兼容vi的所有指令,而且还有一些新的特性在里面. vim的这些优势主要体现在以下几个方 ...
- git-for-windows 安装无图标的问题
git-for-windows.ico 安装无图标的问题 一. 问题表现: 桌面图标与右建菜单图标,所是未知文件的图标, 二. 问题解决: 在shard/git/ copy 一个ico 文件(如git ...
- VC++动态链接库(DLL)编程深入浅出(一)
1.概论 先来阐述一下DLL(Dynamic Linkable Library)的概念,你可以简单的把DLL看成一种仓库,它提供给你一些可以直接拿来用的变量.函数或类.在仓库的发展史上经历了“无库-静 ...
- iOS动画中的物理知识应用之愤慨的小鸟-碰撞检測
碰撞检測 源码:https://github.com/Esdeath/collsion 我相信搞iOS得人.多多少少都知道 弹球这个小游戏. 撞击不同的点,就能改变其运动的轨迹.对于非常多人来说,假设 ...
- 各种常用的CDN加速服务
各种CDN加速网址:点击此处 1.Echar <script type="text/javascript" src="http://echarts.baidu.co ...
- Deploying Docker images via SSH
Original URL:https://advancedweb.hu/2015/04/14/deploying-docker-images-via-ssh/ Background When we b ...
- Web安全系列(四):XSS 的防御
简介 XSS 的防御很复杂,并不是一套防御机制就能就解决的问题,它需要具体业务具体实现. 目前来说,流行的浏览器内都内置了一些 XSS 过滤器,但是这只能防御一部分常见的 XSS,而对于网站来说,也应 ...
- java 表示当前时间的第二天的几点
Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.DAY_OF_YEAR, 1); ...
- python 基础 2.7 range与xrange的区别
#/usr/bin/python #coding=utf-8 #@Time :2017/10/25 19:22 #@Auther :liuzhenchuan #@File :range与xrange的 ...
- 【BZOJ1776】[Usaco2010 Hol]cowpol 奶牛政坛 树的直径
[BZOJ1776][Usaco2010 Hol]cowpol 奶牛政坛 Description 农夫约翰的奶牛住在N (2 <= N <= 200,000)片不同的草地上,标号为1到N. ...