[poj3744] Scout YYF I【概率dp 数学期望】
传送门:http://poj.org/problem?id=3744
令f(i)表示到i,安全的概率。则f(i) = f(i - 1) * p + f(i - 2) * (1 - p),若i位置有地雷,则f(i) = 0.很显然,要用矩阵来加速,矩阵也很好构造,懒得写了,百度图片搜“poj3744”就能看到。注意一下边界的处理。
#include <cstdio>
#include <algorithm>
#include <cstring> const int maxn = 15; int n, a[maxn], ima;
double p, mtx[2][2] = {{0.5, 0.5}, {1.0, 0.0}}, rt[2][2], tem[2][2], ans[2][2]; inline void mul(double a[2][2], double b[2][2]) {
tem[0][0] = a[0][0] * b[0][0] + a[0][1] * b[1][0];
tem[0][1] = a[0][0] * b[0][1] + a[0][1] * b[1][1];
tem[1][0] = a[1][0] * b[0][0] + a[1][1] * b[1][0];
tem[1][1] = a[1][0] * b[0][1] + a[1][1] * b[1][1];
memcpy((void*)b, (void*)tem, sizeof tem);
}
inline void poww(int mi) {
int i;
for (i = 31; mi >> i & 1 ^ 1; --i);
memcpy((void*)rt, (void*)mtx, sizeof mtx);
for (--i; ~i; --i) {
mul(rt, rt);
if (mi >> i & 1) {
mul(mtx, rt);
}
}
} int main(void) {
//freopen("in.txt", "r", stdin);
while (scanf("%d%lf", &n, &p) != EOF) {
mtx[0][0] = p;
mtx[0][1] = 1.0 - p;
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
}
std::sort(a + 1, a + n + 1);
n = std::unique(a + 1, a + n + 1) - a - 1;\
for (int i = 1; i <= n; ++i) {
if (a[i] - a[i - 1] == 1) {
puts("0.0000000");
goto end;
}
}
ans[0][0] = 0.0;
ans[1][0] = 1.0 / (1.0 - p);
for (int i = 1; i <= n; ++i) {
poww(a[i] - a[i - 1] - 1);
mul(rt, ans);
ans[1][0] = ans[0][0];
ans[0][0] = 0.0;
}
printf("%.7f\n", ans[0][0] * p + ans[1][0] * (1.0 - p)); end:;
}
return 0;
}
[poj3744] Scout YYF I【概率dp 数学期望】的更多相关文章
- poj3744 Scout YYF I[概率dp+矩阵优化]
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8598 Accepted: 2521 Descr ...
- POJ-3744 Scout YYF I 概率DP
题目链接:http://poj.org/problem?id=3744 简单的概率DP,分段处理,遇到mine特殊处理.f[i]=f[i-1]*p+f[i-2]*(1-p),i!=w+1,w为mine ...
- POJ3744 Scout YYF I 概率DP+矩阵快速幂
http://poj.org/problem?id=3744 题意:一条路,起点为1,有概率p走一步,概率1-p跳过一格(不走中间格的走两步),有n个点不能走,问到达终点(即最后一个坏点后)不踩坏点的 ...
- poj 3744 Scout YYF I(概率dp,矩阵优化)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5020 Accepted: 1355 Descr ...
- POJ 3744 Scout YYF I 概率dp+矩阵快速幂
题目链接: http://poj.org/problem?id=3744 Scout YYF I Time Limit: 1000MSMemory Limit: 65536K 问题描述 YYF is ...
- poj 3744 Scout YYF 1 (概率DP+矩阵快速幂)
F - Scout YYF I Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- bzoj1415 [Noi2005]聪聪和可可【概率dp 数学期望】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1415 noip2016 D1T3,多么痛的领悟...看来要恶补一下与期望相关的东西了. 这是 ...
- CF 148D D. Bag of mice (概率DP||数学期望)
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests ...
- [poj2096] Collecting Bugs【概率dp 数学期望】
传送门:http://poj.org/problem?id=2096 题面很长,大意就是说,有n种bug,s种系统,每一个bug只能属于n中bug中的一种,也只能属于s种系统中的一种.一天能找一个bu ...
随机推荐
- ArcGIS Engine 中的绘制与编辑
1.线段绘制 基本步骤 构建形状 1. 创建 IPoint IPoint m_Point = new PointClass(); m_Point.PutCoords(x, y); 2. 创建 IPoi ...
- Meteor表单
在本教程中,我们将告诉你如何使用 Meteor 的表单. 文本输入 首先,我们将创建一个 form 元素中文本输入字段和提交按钮. meteorApp/import/ui/meteorApp.html ...
- Jupyter Notebook 基本使用
Jupyter 官网 IPython Interactive Computing IPython Notebook使用浏览器作为界面,向后台的IPython服务器发送请求,并显示结果.在浏览器的界面中 ...
- topcoder srm 553
div1 250pt: 题意:... 解法:先假设空出来的位置是0,然后模拟一次看看是不是满足,如果不行的话,我们只需要关心最后栈顶的元素取值是不是受空白处的影响,于是还是模拟一下. // BEGIN ...
- SQL 主机
SQL 主机 SQL 主机 如果您想要您的网站存储数据在数据库并从数据库显示数据,您的 Web 服务器必须能使用 SQL 语言访问数据库系统. 如果您的 Web 服务器托管在互联网服务提供商(ISP, ...
- JMeter 系列之—-01使用
用Jmeter 做压测,总体与LoadRunner 类似: 一.线程组 1. 线程数 2. 循环次数 单个线程循环次数 3. Ramp-up Period(in seconds) [1]决定多长时间启 ...
- iOS视频流开发(2) — 视频播放
iOS视频流开发(2) — 视频播放 承上篇,本篇文章主要介绍iOS视频播放需要用到的类.以及他们的使用场景和开发中遇到的问题. MPMoviePlayerViewController MP简介 i ...
- Effective JavaScript Item 39 绝不要重用父类型中的属性名
本系列作为Effective JavaScript的读书笔记. 假设须要向Item 38中的Actor对象加入一个ID信息: function Actor(scene, x, y) { this.sc ...
- MUI日期选择控件
MUI的Demo里面有例子,实际做的时候发现日期老是乱码,调了半天,最后发现引用的CSS错误,例子中引用的是 <link href="Css/mui.picker.min.css&qu ...
- 调参侠的末日? Auto-Keras 自动搜索深度学习模型的网络架构和超参数
Auto-Keras 是一个开源的自动机器学习库.Auto-Keras 的终极目标是允许所有领域的只需要很少的数据科学或者机器学习背景的专家都可以很容易的使用深度学习.Auto-Keras 提供了一系 ...