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 ...
随机推荐
- MySQL命令行分号无法结束问题解决
背景:输入一串查询语句,以分号结束,发现没有结束,再打回车,分号,还是不完.什么exit,quit,bye,都不顶用如果要ctrl+C吧,又得退出mysql,一切重来,很麻烦.后来终于发现,引起这种现 ...
- 2019-6-23-WPF-网络-request-的-read-方法不会返回
title author date CreateTime categories WPF 网络 request 的 read 方法不会返回 lindexi 2019-06-23 11:26:26 +08 ...
- 页面头部<meta>中的属性和含义
1<meta name="robots" content="index, follow" /> none:搜索引擎将忽略此网页,等价于noin ...
- 不撞南墙不回头———深度优先搜索(DFS)Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- java基础部分的一些有意思的东西。
${li.key!=''&&li.key!= null}可以直接判断不为空 ${empty li.value}也是不为空. 最近好烦迭代map里的map或者map里的list 后来发现 ...
- C++ 求向量的交集、并集、差集
#include<iostream> #include<stdio.h> #include<list> #include<algorithm> //se ...
- 阿里云POLARDB如何助力轻松筹打造5亿用户信赖的大病筹款平台?
轻松筹首创了“大病救助”模式,帮助了众多病患在第一时间解決了医疗资金等问题,为了从源头解决了医疗资金问题.而在轻松筹这样全球5.5亿用户信赖的大病筹款平台的背后,是日益增长的各种数据.面对这样数据量所 ...
- CENTOS7安装R语言环境
CENTOS7安装R语言环境 yum install texinfo.x86_64 yum install texlive.x86_64 cd /opt wget https://mirrors.tu ...
- MaxCompute 预付费标准版VS套餐版
MaxCompute 于5月7日正式售卖预付费(包年包月)套餐资源,主打存储密集型套餐,一共三个套餐: 存储密集型160套餐 存储密集型320套餐 存储密集型600套餐 本文主要给大家介绍预付标准版和 ...
- H3C 网络号和主机号