POJ 3744 Scout YYF I
分段的概率DP+矩阵快速幂
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4180 | Accepted: 1076 |
Description
Input
Each test case contains two lines.
The First line of each test case is N (1 ≤ N ≤ 10) and p (0.25 ≤ p ≤ 0.75) seperated by a single blank, standing for the number of mines and the probability to walk one step.
The Second line of each test case is N integer standing for the place of N mines. Each integer is in the range of [1, 100000000].
Output
Sample Input
1 0.5
2
2 0.5
2 4
Sample Output
0.5000000
0.2500000
Source
POJ Monthly Contest - 2009.08.23, Simon
如果不用快速幂(TLE的)。。。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int n,mine[];
double p,d1,d2,d3,ans; int main()
{
while(scanf("%d%lf",&n,&p)!=EOF)
{
for(int i=;i<=n;i++)
{
scanf("%d",mine+i);
}
sort(mine,mine++n);
if(mine[]==)
{
printf("0.0000000\n"); continue;
}
else if(n==)
{
printf("1.0000000\n"); continue;
}
bool flag=false;
for(int i=;i<n;i++)
{
if(mine[i]+==mine[i+])
{
printf("0.0000000\n"); flag=true; break;
}
}
if(flag==true) continue;
ans=.;
for(int i=;i<=n;i++)
{
int st=mine[i-]+,ed=mine[i];
d2=.,d1=.;
for(int j=st+;j<=ed;j++)
{
d3=d1*p+d2*(-p);
d2=d1; d1=d3;
}
ans*=(-d3);
}
printf("%.7lf\n",ans);
}
return ;
}
快速幂的。。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; struct Matrix
{
double a[][];
Matrix() {}
Matrix(double A,double B,double C,double D)
{
a[][]=A;a[][]=B;a[][]=C;a[][]=D;
}
Matrix operator* (const Matrix& b) const
{
Matrix temp;
memset(temp.a,,sizeof(temp.a));
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
for(int k=;k<;k++)
{
temp.a[i][j]+=a[i][k]*b.a[k][j];
}
}
}
return temp;
}
Matrix Show()
{
for(int i=;i<;putchar(),i++) for(int j=;j<;putchar(' '),j++) cout<<a[i][j];
}
}; Matrix QuickPow(Matrix m,int n)
{
Matrix E(,,,);
while(n>)
{
if(n&) E=E*m;
m=m*m;
n=n>>;
}
E=E*m;
return E;
} int n,mine[];
double p,ans; int main()
{
while(scanf("%d%lf",&n,&p)!=EOF)
{
for(int i=;i<=n;i++)
scanf("%d",mine+i);
sort(mine,mine+n+);
if(mine[]==)
{
printf("0.0000000\n"); continue;
}
else if(n==)
{
printf("1.0000000\n"); continue;
}
bool flag=false;
for(int i=;i<n;i++)
{
if(mine[i]+==mine[i+])
{
printf("0.0000000\n"); flag=true; break;
}
}
if(flag==true) continue;
ans=.;
for(int i=;i<=n;i++)
{
Matrix m(p,-p,,);
m=QuickPow(m,mine[i]-mine[i-]-);
ans*=-m.a[][];
}
printf("%.7lf\n",ans);
}
return ;
}
POJ 3744 Scout YYF I的更多相关文章
- poj 3744 Scout YYF I(递推求期望)
poj 3744 Scout YYF I(递推求期望) 题链 题意:给出n个坑,一个人可能以p的概率一步一步地走,或者以1-p的概率跳过前面一步,问这个人安全通过的概率 解法: 递推式: 对于每个坑, ...
- 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 I(概率dp,矩阵优化)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5020 Accepted: 1355 Descr ...
- poj 3744 Scout YYF 1 (概率DP+矩阵快速幂)
F - Scout YYF I Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- poj 3744 Scout YYF I (矩阵)
Description YYF -p. Here is the task, given the place of each mine, please calculate the probality t ...
- poj 3744 Scout YYF I (可能性DP+矩阵高速功率)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5062 Accepted: 1370 Description YYF i ...
- POJ 3744 Scout YYF I(矩阵快速幂优化+概率dp)
http://poj.org/problem?id=3744 题意: 现在有个屌丝要穿越一个雷区,雷分布在一条直线上,但是分布的范围很大,现在这个屌丝从1出发,p的概率往前走1步,1-p的概率往前走2 ...
- POJ 3744 Scout YYF I:概率dp
题目链接:http://poj.org/problem?id=3744 题意: 有n个地雷,位置为pos[i]. 在每个位置,你向前走一步的概率为p,向前走两步的概率为1-p. 你的初始位置为1. 问 ...
- poj 3744 Scout YYF I (矩阵快速幂 优化 概率dp)
题目链接 分析&&题意来自 : http://www.cnblogs.com/kuangbin/archive/2012/10/02/2710586.html 题意: 在一条不满地雷的 ...
随机推荐
- CentOS找回root密码
如果忘记了root密码,可以进入单用户模式进行密码重置. 重启系统,在grub的启动菜单中按下e键,然后编辑kernel那一行,在最后的quiet后加上single. 按下Enter后,再按b开机进入 ...
- 加州大学伯克利分校Stat2.3x Inference 统计推断学习笔记: FINAL
Stat2.3x Inference(统计推断)课程由加州大学伯克利分校(University of California, Berkeley)于2014年在edX平台讲授. PDF笔记下载(Acad ...
- CentOS 下安装
2016年12月5日15:25:58 ----------------------------------- 通常情况下在centos下安装软件就用yum. 关键是,使用yum你要知道安装包的名字是什 ...
- “K米” 软件产品评测
第一部分 调研,评测 评测: 第一次上手体验:KTV相信很多人都有去过,大部分包厢只有哦一个点歌台,相信很多人都会烦恼于一堆人挤在小小的点歌台前点歌的样子,还有些人不太好意思跑到点歌台点歌,常常是碰到 ...
- Beta版本冲刺第五天 12.11
一.站立式会议照片: 二.项目燃尽图: Android端 后台 三.项目进展: 成 员 昨天完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 管理员驳回招聘的理由的填写和查看 邮箱验证 ...
- bootstrap学习总结-04 常用标签2
1 表格 Bootstrap为表格设计了漂亮的样式. 1)表格基本实例 任意 <table> 标签添加 .table. <table class="table"& ...
- BZOJ2049: [Sdoi2008]Cave 洞穴勘测 Link-Cut-Tree 模板题
传送门 搞了这么长时间Splay终于可以搞LCT了,等等,什么是LCT? $LCT$就是$Link-Cut-Tree$,是维护动态树的一个很高效的数据结构,每次修改和查询的均摊复杂度为$O(logN) ...
- SSH和SSM项目的打通各个页面的方式
SSH项目: 这里采用的action的形式: 即在表现层为页面在action中配置一个返回值,然后在Struts.xml的配置文件中进行配置. SSM项目中,SpringMVC中利用注解来配置每个页面 ...
- Objective-C复合
正所谓复合,便是定义的这个类中的成员是另外类的实例方法. 也就是把其他对象作为自身的题部分,以提升自身的功能, 就相当于C语言中的函数嵌套.下面是一段代码(多个文件放在一块了): /***Comput ...
- 使用iframe实现图片上传预览效果
原理:将图片上传的页面放在iframe中,这样就可以在iframe中将图片提交到服务器而不需要页面刷新,提交成功后用脚本实现主页面显示上传的图片. Default.aspx: <%@ Page ...