LightOJ 1065 Island of Survival (概率DP?)
题意:有 t 只老虎,d只鹿,还有一个人,每天都要有两个生物碰面,
1.老虎和老虎碰面,两只老虎就会同归于尽
2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方
3.人和鹿碰面,人可以选择杀或者不杀该鹿
4.鹿和鹿碰面,没事
问人存活下来的概率
析:最后存活肯定是老虎没了,首先可以用概率dp来解决,dp[i][j] 表示 还剩下 i 考虑, j 只鹿存活的概率是多少。
然后每次分析这几种情况即可。
还有一种思路就是只要考虑老虎没了,只要老虎没了就能存活,只要计算老虎全死完的概率就好,首先如果老虎是奇数,是肯定死不完的。老虎是偶数才有可能死完。
代码如下:
概率DP:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} double dp[maxn][maxn]; int main(){
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
scanf("%d %d", &n, &m);
memset(dp, 0, sizeof dp);
dp[n][m] = 1.0;
for(int i = n; i; --i)
for(int j = m; j >= 0; --j){
double sum = i*(i-1)/2 + i*j + i;
if(i >= 2) dp[i-2][j] += dp[i][j]*i*(i-1)/2.0/sum;
if(i > 0 && j > 0) dp[i][j-1] += dp[i][j]*i*j/sum;
}
double ans = 0.0;
for(int i = 0; i <= m; ++i) ans += dp[0][i];
printf("Case %d: %.10f\n", kase, ans);
}
return 0;
}
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} double solve(int x){
if(x & 1) return 0.0;
double ans = 1.0;
while(x){
ans *= (x-1.0) / (x+1.0);
x -= 2;
}
return ans;
} int main(){
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
scanf("%d %d", &n, &m);
printf("Case %d: %.10f\n", kase, solve(n));
}
return 0;
}
LightOJ 1065 Island of Survival (概率DP?)的更多相关文章
- 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 kin ...
- LightOJ - 1265 Island of Survival —— 概率
题目链接:https://vjudge.net/problem/LightOJ-1265 1265 - Island of Survival PDF (English) Statistics F ...
- 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 ...
随机推荐
- 关于 SMT 一个重要提示
关于 SMT 一个重要提示 温度曲线是对应的具体的PCB的最差焊盘位置处的所用焊锡膏对应的熔化曲线.从这种角度来观察,我想你会明白我的意思的. https://www.amobbs.com/forum ...
- ajax同步异步
test.html <a href="javascript:void(0)" onmouseover="testAsync()"> asy.js f ...
- java中String和char的区别
首先来看一下Java的数据类型.Java 包括两种数据类型: 1.原始数据类型(primitive data type):byte,short, char, int, long,float,doubl ...
- delphi 2010安装unidac
UniDAC是一个功能强大的非可视化跨数据库的数据访问组件,可用于Delphi,Delphi for .NET,C++Builder,and Lazarus (Free Pascal).它提供了对流行 ...
- TCP协议中的序列号
TCP 协议工作在OSI的传输层,是一种可靠的面向连接的数据流协议,TCP之所以可靠,是因为它保证了传送数据包的顺序.顺序是用一个序列号来保证的.响应包内也包括一个序列号,表示接收方准备好这个序列号的 ...
- 从request获取各种路径总结 request.getRealPath("url")
转载:http://blog.csdn.net/piaoxuan1987/article/details/8541839 equest.getRealPath() 这个方法已经不推荐使用了,代替方法是 ...
- windows右键打开方式里面添加新的应用程序
1.打开注册表编辑器.打开运行窗口,快捷键,开始+R.输入“regedit”,回车确定. 2.进入注册表编辑器的HKEY_CLASSES_ROOT文件夹下的*子文件夹下的shell文件夹. 3.右键s ...
- NetBeans+Xdebug调试原理
使用Xdebug的远程调试,Xdebug作为一个嵌入到PHP的程序,扮演着客户端的角色,而IDE则作为服务器.下面的动态图展示了连接建立的过程. 服务端的IP为10.0.1.2, 使用HTTP协议,端 ...
- scikit-learn和tensorflow的区别
1.功能不同 Scikit-learn(sklearn)的定位是通用机器学习库,而TensorFlow(tf)的定位主要是深度学习库.一个显而易见的不同:tf并未提供sklearn那种强大的特征工程, ...
- krpano之字幕添加
字幕是指介绍语音的字幕,字幕随着语音的播放而滚动,随语音暂停而暂停.字幕添加的前提是用之前的方法添加过介绍语音. 原理: 字幕层在溢出隐藏的父元素中向右滑动,当点击声音控制按钮时,字幕位置被固定,再次 ...