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 ...
随机推荐
- python Python程序的架构
- 《mysql必知必会》笔记1(检索、排序、过滤、计算、汇聚、分组)
一:了解SQL 1:列是表中的字段,所有表都由一个或多个列组成的.行是表中的记录,表中的数据都按行存储. 2:表中每一行都应该有可以唯一标识自己的一列或一组列.主键(一列或一组列),其值能够唯一区分每 ...
- Mysql Command
数据库备份: mysqldump -uroot -p -h 192.168.1.190 --default-character-set=utf8 $dbname > backup_db.sql ...
- 什么是Hessian协议呢?
什么是Hessian协议呢? 目前,Web服务技术是解决异构平台系统的集成及互操作问题的主流技术. 它所基于的XML已经是Internet上交换数据的实际标准,基于通用的进程间通信协议和网络传输协议屏 ...
- Javascript中的定时调用函数setInterval()和setTimeout()
首先介绍这两个函数 一.setInterval() 按照指定的周期来调用函数或表达式,执行多次.(时间单位:ms) timer = setInterval("content =documen ...
- 【小程序案例】支付宝小程序-MQTT模器,IoT设备通过WSS接入阿里云IoT物联网平台
支付宝小程序-MQTT模拟器通过WSS接入阿里云IoT物联网平台 小程序效果: 1. 准备工作 1.1 注册阿里云账号 开通阿里云账号,并通过支付宝实名认证 https://www.aliyun.co ...
- 2016国产开源软件Top100(Q1)
2016国产开源软件Top100(Q1) 随着互联网的发展.开放标准的普及和虚拟化技术的应用等诸多IT新领域的创新及拓展,开源技术凭借其开放性.低成本.稳定性.灵活性.安全性和技术创新性等特点迅速走向 ...
- 2013-4-3 C#中alt键不是Keys.Alt 而是 Keys.LMenu
2013-4-3 C#中alt键不是Keys.Alt而是Keys.LMenu
- g++ 编译单个文件和多个文件
转载:https://www.cnblogs.com/battlescars/p/cpp_linux_gcc.html 1.单个源文件生成可执行程序 下面是一个保存在文件 helloworld.cpp ...
- theadClasses设置Bootstrap Table表头样式
通过theadClasses属性设置表头样式. thead-light设置灰色背景 //bootstrap table初始化数据 itxst.com $('#table').bootstrapTabl ...