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 题意: 在一条不满地雷的 ...
随机推荐
- 帝国cms制作手机网站
1.操作前,我们需要先对网站数据库进行备份. 接下来我们添加手机站的模板组.点击"模板", 选择"模板组管理"中的"导入/导出模板组",然后 ...
- gvim e303 无法打开 “[未命名]“的交换文件,恢复将不可能
今天vim出现:“gvim e303 无法打开 “[未命名]“的交换文件,恢复将不可能” 解决办法: 修改你的.vimrc,增加下面的一行: set directory=.,$TEMP "默 ...
- JSP实现数据传递与保存
业务逻辑: 1.登陆login.jsp 2.判断登陆是否成功check.jsp 3.登陆成功页面newsDetail.jsp 4.登陆失败转发到login.jsp 代码如下: <%@ page ...
- 【Alpha版本】冲刺-Day6
队伍:606notconnected 会议时间:11月14日 会议总结 张斯巍(433) 今天安排:学习UI设计 完成度:100% 明天计划:上传界面设计 遇到的问题:无 感想:刚开始学的时候,都是从 ...
- Xcode中插件在Xcode更新之后解决方法
>新的解决方法地址:这里 但凡是更新了Xcode的版本,之前安装的Xcode的插件都不会使用,例如:XAlign或者猫神的VVDocument-Xcode插件 解决方法有很多而且很多地方都贴出来 ...
- context.Request.Files为NULL问题 在实现图片上传功能的时候出现在ashx等处理页面出现context.Request.Files为NULL异常,有几点需要注意:
.在客户端可以将form用submit提交,如下: <%@ Page Language="C#" AutoEventWireup="true" CodeF ...
- JAVA第三周课后作业
JAVA课后作业 一.枚举类型 代码: enum Size{SMALL,MEDIUM,LARGE}; public cl ass EnumTest { public static void main( ...
- linux中快速清空文件内容的几种方法
这篇文章主要介绍了linux中快速清空文件内容的几种方法,需要的朋友可以参考下 $ : > filename $ > filename $ echo "" > f ...
- JavaScript 日历
效果图: <html> <head> <script language="javascript"> /*@ 解题思路: .计算本月有多少天(先要 ...
- Python + OpenCV2 系列:1 - 配置
Python+OpenCV2+Eclipse+Windos 8.1(32bits): 最初的目的是做图像处理,opencv强大的社区支持,让我想从matlab转到opencv框架下进行试验,而Pyth ...