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 ...
随机推荐
- centos6.5后台进程的切换
1.运行.sh文件 直接用./sh 文件就可以运行,但是如果想后台运行,即使关闭当前的终端也可以运行的话,需要nohup命令和&命令. (1)&命令 功能:加在一个命令的最后,可以把这 ...
- WPF TextBox提示文字设定
WPF TextBox框提示文字,鼠标划入提示文字消失 <TextBox Width=" VerticalContentAlignment="Center" Bor ...
- Vim学习与总结
1. :w 后面可以加文件名 2. 使用hjkl 来移动光标,当然你也可以使用箭头.j就是向下的箭头,k是向上,h向左, l向右 3. :help <command> → 显示相关命令的 ...
- 设备 VMnet0 上的网络桥接当前未在运行。
早上,我打开我的虚拟机,却发现一个问题, 桥接网络怎么都连接不上. 报的是如下的错误 ------------------------------ 设备 VMnet0 上的网络桥接当前未在运行.该虚拟 ...
- 通过 FastAdmin 理解开源软件
通过 FastAdmin 理解开源软件 开源软件 ≠ 免费软件,免费是遵循其开源协议下的一个特性. 开源软件虽然免费,但服务是可以收费的,因为房子要钱. 开源的目的是为了用户更自由. 做开源每天会遇到 ...
- SqlSugar 笔记
分组: 日期分组一: var result = await temp .GroupBy("date_format(Day,'%Y-%m')") .Select(s => ne ...
- spring配置文件各个属性详解
一.引用外部属性文件 <bean id="propertyConfigurer" class="org.springframework.beans.factory. ...
- oracle函数 LPAD(c1,n[,c2])
[功能]在字符串c1的左边用字符串c2填充,直到长度为n时为止 [参数]C1 字符串 n 追加后字符总长度 c2 追加字符串,默认为空格 [返回]字符型 [说明]如果c1长度大于n,则返回c1左边n个 ...
- 05Redis入门指南笔记(持久化)
Redis的强劲性能很大程度上是由于将所有数据都存储在了内存中,然而当Redis重启后,所有存储在内存中的数据就会丢失.在一些情况下,希望Redis能将数据从内存中以某种形式同步到硬盘中,使得重启后可 ...
- DAMICON'S LIST OF OPEN SOFTWARE
http://www.damicon.com/resources/opensoftware.html DAMICON'S LIST OF OPEN SOFTWARE This List of Open ...