【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. ...
随机推荐
- matplotlib之pyplot 学习示例
现在通过numpy和matplotlib.pyplot 在Python上实现科学计算和绘图,而且和matlab极为相像(效率差点,关键是方便简单) 这里有大量plots代码例子. 1. 简单的绘图( ...
- dubbo之只订阅及只注册
只订阅 问题 如果有两个镜像环境,两个注册中心,有一个服务只在其中一个注册中心有部署,另一个注册中心还没来得及部署,而两个注册中心的其它应用都需要依赖此服务,所以需要将服务同时注册到两个注册中心,但却 ...
- VS2013配置编译Caffe-Win10_X64
原文链接:http://blog.csdn.net/joshua_1988/article/details/45036993 有少量修改................ 2014年4月的时候自己在公司 ...
- (转)基于MVC4+EasyUI的Web开发框架经验总结(14)--自动生成图标样式文件和图标的选择操作
http://www.cnblogs.com/wuhuacong/p/4093778.html 在很多Web系统中,一般都可能提供一些图标的选择,方便配置按钮,菜单等界面元素的图标,从而是Web系统界 ...
- BRAFT EDITOR富文本编辑器
https://braft.margox.cn/demos/basic 官方文档 import React from 'react' import Uploading from '../Upl ...
- 【转载】使用IntelliJ IDEA提示找不到struts-default文件
创建strus,参考文如下: https://blog.csdn.net/u010358168/article/details/79769137 使用IntelliJ IDEA创建struts2工程时 ...
- 【udacity】机器学习-神经网络
Evernote Export 1.神经网络 神经元 细胞的主体称为细胞体,然后有轴突.突触 他们构建的方式是可以调整的 我们会有一些输入的放电信号视为放电频率或输入的强度 X1w1X2w2X ...
- 【剑指Offer】6、旋转数组的最小数字
题目描述: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5 ...
- Linux 系统查看命令
1. linux CPU大小cat /proc/cpuinfo |grep "model name" && cat /proc/cpuinfo |grep &quo ...
- safari浏览器click事件要点击两次才有响应出现闪烁
闪烁问题 由于在iOS Safari上click事件存在300ms响应延时,所以为touch事件添加样式,会和click事件默认样式叠加而产生闪烁问题. 因为ios safari浏览器中对触摸事件的响 ...