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 ...
随机推荐
- 让超出div内容的显示滚动条:overflow:auto,以及overflow其它属性
css的属性,以前没用过遇到了,记录一下: 虽然layui本来自带这个处理,但是为了灵活,抛弃layui原有的加载,只是用layui的样样式,就要使用到这个css属性 总结overflow属性: /* ...
- SDUT_2502:火星计数法
火星人的计数规则里只有a,b,c,d四个字母,计数规则从小到大是 a,b,c,d,aa,ab,ac,ad,ba,……. 给出来由a,b,c,d四种字母组成的火星数字,算出该数字是第几个(从1开始). ...
- 实用的cmd命令
1.打开iis服务器:inetmgr 2.远程连接:mstsc 3.注册表:regedit.exe
- c++第四次作业:继承
继承与派生 基本概念和语法 概念 继承与派生是同一过程从不同角度看 保持已有的特性而构造新类的过程称为继承. 在已有类的基础上新增自己的特性而产生新类的过程为派生. 被继承的已有类称为基类(父类) 派 ...
- iOS开发 分享到QQ空间提示"分享失败 应用不存在"
本人遇到该问题的原因是配置SDK初始化时的APPID错误,可以参考下shareSDK的集成文档中的一段话: 可选:支持QQ所需的相关配置及代码 登录QQ互联(http://connect.qq.com ...
- IoT SaaS加速器——助力阿尔茨海默病人护理
场景介绍 阿尔茨海默病,是导致中老年人认知功能障碍的最常见疾病之一,是发生在老年期及老年前期的一种原发性退行性脑病.据估计,全世界痴呆症患者数量为4700万,到2030年将达到7500万人.痴呆症患者 ...
- 「BZOJ1005」[HNOI2008] 明明的烦恼
「BZOJ1005」[HNOI2008] 明明的烦恼 先放几个prufer序列的结论: Prufer序列是一种对有标号无根树的编码,长度为节点数-2. 具体存在无根树转化为prufer序列和prufe ...
- 「BZOJ2654」tree
「BZOJ2654」tree 最小生成树+二分答案. 最开始并没有觉得可以二分答案,因为答案并不单调啊. 其实根据题意,白边的数目肯定大于need条,而最小生成树的白边数并不等于need(废话),可以 ...
- PHP 手机短信验证码 laravel 实现流程
https://blog.csdn.net/uknow0904/article/details/80336941 本人在自己博客(Laravel)的注册部分 使用手机号注册,需要发送短信验证码. 使用 ...
- redis 清除缓存