【POJ 3744】 Scout YYF I
【题目链接】
http://poj.org/problem?id=3744
【算法】
概率DP + 矩阵乘法
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std; int i,n;
double p,g,ans;
double x[]; struct Matrix
{
double mat[][];
} m; inline Matrix multipy(Matrix &a,Matrix b)
{
int i,j,k;
Matrix res;
memset(res.mat,,sizeof(res.mat));
for (i = ; i <= ; i++)
{
for (j = ; j <= ; j++)
{
for (k = ; k <= ; k++)
{
res.mat[i][j] += a.mat[i][k] * b.mat[k][j];
}
}
}
return res;
}
inline Matrix power(Matrix a,int n)
{
int i,j;
Matrix res,b = a;
for (i = ; i <= ; i++)
{
for (j = ; j <= ; j++)
{
res.mat[i][j] = (i == j);
}
}
while (n)
{
if (n & ) res = multipy(res,b);
b = multipy(b,b);
n >>= ;
}
return res;
} int main()
{ while (scanf("%d%lf",&n,&p) != EOF)
{
for (i = ; i <= n; i++) scanf("%lf",&x[i]);
sort(x+,x+n+);
m.mat[][] = p; m.mat[][] = - p;
m.mat[][] = ; m.mat[][] = ;
ans = 1.0;
x[] = ;
for (i = ; i <= n; i++)
{
m = power(m,x[i]-x[i-]-);
g = m.mat[][];
ans *= ( - g);
m.mat[][] = p; m.mat[][] = - p;
m.mat[][] = ; m.mat[][] = ;
}
printf("%.7lf\n",ans);
} return ; }
【POJ 3744】 Scout YYF I的更多相关文章
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
随机推荐
- for 循环练习题
X3 * 6528 = 3X * 8256X为一个数字 填入一个数字 使等式成立 for (var x=1;x<=9&&x>0;x++) { if ((x*10+3)*65 ...
- 从Hive1.0升级到Hive2.0(删除hive1.x中的元数据, 并不是数据迁移)
软件环境: linux系统: CentOS6.7 Hadoop版本: 2.6.5 zookeeper版本: 3.4.8 主机配置: 一共m1, m2, m3这五部机, 每部主机的用户名都为centos ...
- hibernate_02_session介绍
什么是session? hibernate的session对象就相当于jdbc的connection.我们对数据库的操作(增删改等)都是使用的session方法. 写一个java类 package c ...
- 【python】random
1.random 和其他语言一样,返回大于等于0.小于1的浮点数 2.uniform(a,b) 返回大于等于a.小于等于b的浮点数 3.randint(a,b) 这个很好理解,返回一个介于a和b之间的 ...
- win2008系统日志不断出现【审核失败】
win2008系统日志不断出现[审核失败] [现象] 今天查看windows日志,在 -安全- 发现不断有消息刷出,显示 -审核失败- 事件ID为4624 的记录 每分钟大概刷新8条消息(如 ...
- AI不与人为敌
业界广为流传着一句话:有多少人工就有多少智能. 其实还应该有一句话:有多少付出就因该有多少回报.公正是世界永恒的话题. 一.人工智能还是人工愚蠢 科技从来没有善恶,也不会杀人,愚蠢的人比聪明的人做的错 ...
- OpenCV实现灰度直方图和直方图拉伸
原文链接:http://blog.csdn.net/xiaowei_cqu/article/details/7600666 如有疑问或者版权问题,请移步原作者或者告知本人. 灰度直方图是数字图像中最简 ...
- SLAM: 图像角点检测的Fast算法(OpenCV文档)
官方链接:http://docs.opencv.org/trunk/doc/py_tutorials/py_feature2d/py_fast/py_fast.html#fast-algorithm- ...
- structure vs class in swift language
Both class and structure can do: Define properties to store values Define methods to provide functio ...
- Scala: Types of a higher kind
One of the more powerful features Scala has is the ability to generically abstract across things tha ...