POJ 3744 概率 + 分段 + 数学推导 + 快速幂
来源:互联网 发布:黑马程序员 课程表 编辑:程序博客网 时间:2024/05/01 00:42
传送门 :
题解
这里把每两个mine之间分段, 每两个mine之间安全走过到末尾概率pi分别求出(快速幂), 越过的概率是pi*(1 - p)(一次走两步)
推导过程
AC code:
#include<iostream>#include<cstring>#include<cmath>#include<iomanip>#include<cstdio>#include<algorithm>using namespace std;int x[30], n;double p, ans;double quick_multi(int b) { double res = 1.0, tmp = p - 1.0; while (b) { //cout << res << endl; if (b & 1) res *= tmp; b >>= 1; tmp *= tmp; } return res;}int main() { //freopen("in.txt", "r", stdin); while (cin >> n >> p) { for (int i = 1; i <= n; ++i) cin >> x[i]; x[0] = 0; ans = 1; sort(x, x + n + 1); for (int i = 1; i <= n; ++i) { int t = x[i] - x[i - 1] - 1;//分段快速幂 ans *= (1.0 - quick_multi(t)) / (2.0 - p); if (fabs(ans) < 1e-6) break;//概率为0直接退出就可以了 ans *= 1.0 - p;//越过x[i]处的mine } cout << fixed << setprecision(7) << ans << endl; } return 0;}
0 0
- POJ 3744 概率 + 分段 + 数学推导 + 快速幂
- POJ 3744 概率dp+矩阵快速幂
- HDU 4565 (数学推导 矩阵快速幂)
- POJ 1183 数学推导
- POJ 3744 分段矩阵乘法优化求概率
- poj-3734(矩阵快速幂+推导)
- poj 3744 Scout YYF I(概率DP&矩阵快速幂)
- poj 3744 Scout YYF I(概率dp+矩阵快速幂)
- POJ 3744 Scout YYF I 概率DP + 矩阵快速幂
- poj 3744 Scout YYF I(概率dp+矩阵快速幂)
- Poj 3744 Scout YYF I 概率DP+快速幂
- POJ 3744 Scout YYF I 概率dp+矩阵快速幂
- POJ 3744 Scout YYF I 概率dp 矩阵快速幂
- POJ 3744 Scout YYF I (概率DP+矩阵快速幂)
- 矩阵快速幂应用于概率DP POJ 3744
- POJ 3744 水概率dp+水矩阵快速幂
- poj 3744 概率dp 矩阵快速幂优化
- POJ 3744 Scout YYF(概率DP+矩阵快速幂)
- 电脑上用adb连接到Android设备(开发板也可)
- Caffe部署中的几个train-test-solver-prototxt-deploy等说明<二>
- 十大滤波算法
- #611 – 在退出事件中设置退出码(Set Application Exit Code in Exit Event Handler)
- Android 中数据库的简单使用
- POJ 3744 概率 + 分段 + 数学推导 + 快速幂
- 浅谈RxJava与2.0的新特性
- struts1 ActionForm类及表单数据验证
- Java NIO系列教程(一) Java NIO 概述
- TX
- Maven的安装与配置
- 12. Integer to Roman
- BZOJ1984: 月下“毛景树”
- 大鱼海棠8 银联电子支付报文说明