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 ...
随机推荐
- 六、动态增加方法Category
1.概念:Category可以动态为已经存在的类增加一个方法,可以不改动原有的类. 2. 如何创建一个Category类创建一个文件,选择Objective-C category,点next取名时,要 ...
- 如何将list转为json?
- Windows客户端C/C++编程规范“建议”——风格
本文来自:http://blog.csdn.net/breaksoftware/article/details/37935459 命名风格也非常适用于C# 9 风格 9.1 优先使用匈牙利命名法 等级 ...
- 微软职位内部推荐-SW Engineer II for Skype
微软近期Open的职位: We are the Skype Beijing team. Skype division drives the communications strategy for Mi ...
- 开源(免费)三维 GIS(地形,游戏)
先写想法: 想做个简单的地形漫游,于是考虑在ww直接开发,或找个控件形式的开发组件. 最大的期望有: 1. 支持google的sketchup,快速智能三维建模 2. 设计模式做好点,最好先做成组件形 ...
- cannot change version web module 3.0
eclipse如何修改dynamic web module version 由于从SVN down下来的工程java及tomcat 版本比本地高,导致工程不能编译,报以下错误. 1.Java comp ...
- 基于Html5的移动端开发框架的研究
下面统计信息部分来自网络,不代表个人观点.请大家参考. 基于Html5移动端开发框架调查 序号 框架 简介 优点 缺 ...
- [CareerCup] 6.2 Dominos on Chess Board 棋盘上的多米诺
6.2 There is an 8x8 chess board in which two diagonally opposite corners have been cut off. You are ...
- [CareerCup] 7.6 The Line Passes the Most Number of Points 经过最多点的直线
7.6 Given a two-dimensional graph with points on it, find a line which passes the most number of poi ...
- PLC梯形图编程练习
在PLC培训软件中完成如下两个练习,并把对应的梯形图程序发表在博客上. 交通灯控制 在如下图的场景中,打开SW1开关后,交通灯控制器开始工作,关闭SW1则控制器停止工作. SW2为控制模式选择开关: ...