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 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
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只小鹿,老虎遇到老虎会自相残杀,老虎遇到小鹿或者遇到你就会痛下杀手,你遇到小鹿可以选择杀或者不杀,每次随机两只生物相遇,问你能活到最后的最大几率.
思路
dp[i][j]表示还剩下i只老虎,j只小鹿的概率.
转移比较简单,处理选到两只小鹿等于没选,所以先把这部分概率去掉.
但是在AC之后的测试中,发现无论小鹿的数量怎么变,最后的概率都是没有变化的.
想了一下确实如此,因为小鹿完全可以把选到小鹿的动作都看做无效的.
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime> #define fuck(x) cerr<<#x<<" = "<<x<<endl;
#define debug(a, x) cerr<<#a<<"["<<x<<"] = "<<a[x]<<endl;
#define lson l,mid,ls
#define rson mid+1,r,rs
#define ls (rt<<1)
#define rs ((rt<<1)|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int loveisblue = ;
const int maxn = ;
const int maxm = ;
const int inf = 0x3f3f3f3f;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); double dp[maxn][maxn];
int main() {
ios::sync_with_stdio(true);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif int T;
scanf("%d",&T);
int cas = ;
while (T--){
int n,m;
scanf("%d%d",&n,&m);
if(n&){
printf("Case %d: 0\n",++cas);
continue;
}
memset(dp,,sizeof(dp));
dp[n][m]=;
for(int i=n;i>=;i-=){
for(int j=m;j>=;j--){
double sum= ;
if(i>)sum = 1.0-1.0*j*(j+)/(i+j+)/(i+j);
if(i!=){
double tmp = 1.0*i*(i-)/(i+j+)/(i+j)/sum;
dp[i-][j]+=dp[i][j]*tmp;
}if(j!=){
double tmp = 2.0*i*j/(i+j+)/(i+j)/sum;
dp[i][j-]+=dp[i][j]*tmp;
}if(i==&&j!=){
dp[i][j-]+=dp[i][j];
}
}
}
printf("Case %d: %.7f\n",++cas,dp[][]);
}
return ;
}
LightOJ - 1265 Island of Survival (概率dp)的更多相关文章
- LightOJ - 1265 Island of Survival —— 概率
题目链接:https://vjudge.net/problem/LightOJ-1265 1265 - Island of Survival PDF (English) Statistics F ...
- LightOJ 1065 Island of Survival (概率DP?)
题意:有 t 只老虎,d只鹿,还有一个人,每天都要有两个生物碰面,1.老虎和老虎碰面,两只老虎就会同归于尽 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方 3.人和鹿碰面,人可以选择杀或者不杀该鹿4. ...
- 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.人 ...
- Island of Survival 概率
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> ...
- LightOJ 1030 Discovering Gold(概率DP)题解
题意:1~n每格都有金子,每次掷骰子,掷到多少走几步,拿走那格的金子,问你金子的期望 思路:dp[i]表示从i走到n金子的期望,因为每次最多走1<=x<=6步,所以dp[i] = a[i] ...
- lightoj 1248-G - Dice (III) (概率dp)
题意:给你n个面的骰子,问扔出所有面的期望次数. 虽然这题挺简单的但还是要提一下.这题题目给出了解法. E(m)表示得到m个不同面的期望次数. E(m+1)=[((n-m)/n)*E(m)+1]+(m ...
随机推荐
- docker 常用的命令
1.运行容器 sudo docker run -d -t -p : --name demo ubuntu:16.04 2.删除容器 sudo docker rm -f demo 3.在容器中安装必备软 ...
- Hdu 1867 KMP
题目链接 题目意思: 给出两个字符串a, b, 求最长的公共字串c, c是a的后缀,也是b的前缀. 本题没有具体说明哪个字符串是文本串和匹配串, 所以都要考虑 思路: 查找的时候, 当文本串结束的时候 ...
- python系列之(1)BeautifulSoup的用法
好久没更新博客了.打算写一个python的爬虫系列及数据分析.falg也不能随便立,以免打脸. python爬取内容,是过程,分析数据是结果,最终得出结论才是目的.python爬虫爬取了内容,一般都是 ...
- HZOJ 老司机的狂欢
比较神仙的一道题. 第一问还比较简单一点: t是否可行是单调的,考虑二分. 考虑对于两个人i,j合法的条件,设x(i)<x(j),那么$x(i)+\frac {a(i)*t^2}{2} < ...
- Creating a Pulsing Circle Animation
原文 https://www.kirupa.com/animations/creating_pulsing_circle_animation.htm Outside of transitions th ...
- laravel中如何实现验证码验证及使用
开发环境: laravel5.5 php7.1.11 mysql 验证码 是防止恶意破解密码.刷票.论坛灌水.刷页的手段.验证码有 多种类型. 现在我给大家实现如何使用图片验证码,其原理是让用户输入一 ...
- golang micro client 报错500 {"id":"go.micro.client","code":408,"detail":"call timeout: context deadline exceeded","status":"Request Timeout"}
go micro web端连接services时,第一次访问提示500(broken pipe),排查发现客户端请求services时返回 {"id":"go.micro ...
- Libev源码分析10:libev中poll的用例
在Libev中,使用poll作为backend时,涉及到下面几种数据结构: int *pollidxs; int pollidxmax; struct pollfd *polls; int pollm ...
- git学习一——Pro-Git
1.配置用户名,邮箱 git config --global user.name "Mike" git config --global user.email Mike@exampl ...
- Python字节码介绍
了解 Python 字节码是什么,Python 如何使用它来执行你的代码,以及知道它是如何帮到你的.如果你曾经编写过 Python,或者只是使用过 Python,你或许经常会看到 Python 源代码 ...