POJ3744Scout YYF I(求概率 + 矩阵快速幂)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6757 | Accepted: 1960 |
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
precision to 7 digits after the decimal point.
Sample Input
1 0.5
2
2 0.5
2 4
Sample Output
0.5000000
0.2500000
Source
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct Mat
{
double mat[][];
};
int x[],n;
Mat operator*(Mat a,Mat b)
{
Mat c;
for(int i = ; i < ; i++)
{
for(int j = ; j < ; j++)
c.mat[i][j] = ;
}
for(int i = ; i < ; i++)
{
for(int j = ; j < ; j++)
{
for(int k = ; k < ; k++)
c.mat[i][j] += a.mat[i][k] * b.mat[k][j];
}
}
return c;
}
Mat operator^(Mat a, int k)
{
Mat c;
for(int i = ; i < ; i++)
for(int j = ; j < ; j++)
c.mat[i][j] = (i == j);
while(k)
{
if(k % )
c = c * a;
a = a * a;
k = k / ;
}
return c;
}
int main()
{
double p;
while(scanf("%d%lf", &n,&p) != EOF)
{
for(int i = ; i < n; i++)
scanf("%d", &x[i]);
sort(x, x + n);
Mat tt,temp;
temp.mat[][] = tt.mat[][] = p;
temp.mat[][] = tt.mat[][] = - p;
temp.mat[][] = tt.mat[][] = ;
temp.mat[][] = tt.mat[][] = ; temp = tt ^ (x[] - );
double ans = ;
ans *= ( - temp.mat[][]);
for(int i = ; i < n; i++)
{
if(x[i] == x[i - ])
continue;
temp = tt ^ (x[i] - x[i - ] - ); // 因为要从x[i - 1] + 1开始走,x[i - 1] 是雷
ans *= ( - temp.mat[][]);
}
printf("%0.7lf\n", ans);
}
return ;
}
POJ3744Scout YYF I(求概率 + 矩阵快速幂)的更多相关文章
- 刷题总结—— Scout YYF I(poj3744 矩阵快速幂+概率dp)
题目: Description YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate int ...
- Scout YYF I (概率+矩阵快速幂)
YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate into the enemy's ba ...
- 【XSY2612】Comb Avoiding Trees 生成函数 多项式求逆 矩阵快速幂
题目大意 本题的满二叉树定义为:不存在只有一个儿子的节点的二叉树. 定义一棵满二叉树\(A\)包含满二叉树\(B\)当且经当\(A\)可以通过下列三种操作变成\(B\): 把一个节点的两个儿子同时删掉 ...
- HDU4565-数学推导求递推公式+矩阵快速幂
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4565 我们带着这个根号是没法计算的 我们仔细观察一下,(a+sqrt(b))^n用二项式定理展开,我 ...
- Just Oj 2017C语言程序设计竞赛高级组A: 求近似值(矩阵快速幂)
A: 求近似值 时间限制: 1 s 内存限制: 128 MB 提交 我的状态 题目描述 求⌊(5–√+6–√)2n⌋⌊(5+6)2n⌋%9932017. 例如:n=1,(5–√+6–√)2( ...
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Coin 概率+矩阵快速幂
题目链接: https://nanti.jisuanke.com/t/17115 题意: 询问硬币K次,正面朝上次数为偶数. 思路: dp[i][0] = 下* dp[i-1][0] + 上*dp[i ...
- HDU 3221 矩阵快速幂+欧拉函数+降幂公式降幂
装载自:http://www.cnblogs.com/183zyz/archive/2012/05/11/2495401.html 题目让求一个函数调用了多少次.公式比较好推.f[n] = f[n-1 ...
- 2019牛客多校第五场 B - generator 1 矩阵快速幂+十倍增+二进制倍增优化
B - generator 1 题意 给你\(x_{0}.x_{1}.a.b.b.mod\),根据\(x_{i} = a*x_{i-1} + b*x_{i-2}\)求出\(x_{n}\) 思路 一般看 ...
- poj4474 Scout YYF I(概率dp+矩阵快速幂)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4100 Accepted: 1051 Descr ...
随机推荐
- 一个简单的python爬虫,以豆瓣妹子“http://www.dbmeizi.com/category/2?p= ”为例
本想抓取网易摄影上的图,但发现查看html源代码时找不到图片的url,但firebug却能定位得到.(不知道为什么???) 目标是抓取前50页的爆乳图,代码如下: import urllib2,url ...
- usb驱动开发2之代码地图
USB只是Linux庞大家族里的一个小部落,host controller是它们的族长,族里的每个USB设备都需要被系统识别.下图显示包含一个USB接口的USB鼠标导出的结果. USB系统中的第一个U ...
- 【MySQL】Linux MySQL学习记录
1.查看日志存放路径 show variables like 'general_log_file'; 2.查看日志是否开启 show global variables like 'log_bin%'; ...
- 关于ZIP大文件压缩
实测:4.76 GB一个单文件压缩没有什么问题. import java.io.File; import java.io.FileInputStream; import java.io.FileOut ...
- 点击劫持(CLICKJACKING)与X-FRAME-OPTIONS HEADER
转载: http://www.tuicool.com/articles/mqUBfa 目录 前言 1.1 点击劫持(clickjacking attacks) 1.2 Frame Bursters. ...
- 虚拟现实的三维时态GIS模式研究
- Log4net Dll用法
在导入Log4net的过程中,遇到一两个小bug. 开发平台必须是NET4 而不能是net4 client profile Log4Helper 里面的Namespace要和我们建立项目的名称一致. ...
- C#实现对指定文件夹中文件按修改时间排序
string path = "~/Document/Introduction/团队管理制度/"; DirectoryInfo dirinfo = new Di ...
- Spring验证的错误返回------BindingResult
Spring验证的错误返回------BindingResult 参考资料:http://www.mkyong.com/spring-mvc/spring-mvc-form-errors-tag-ex ...
- Cordova开发环境的搭建
Cordova开发环境的搭建 原文地址:http://imziv.com/blog/article/read.htm?id=66 Cordova为目前做混合式开发中比较受欢迎的一个解决方案了,并且拥有 ...