【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. ...
随机推荐
- [hihocoder][Offer收割]编程练习赛59
替换函数 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #includ ...
- CentOS 安装dotNetCore
如果要在CentOS上运行.net Core程序,必须安装.net Core Sdk 具体安装 方法,可以参考微软官方站点说明,非常详细: 1)百度搜索 .Net Core 2)先择CentOS版本: ...
- asp.net ajax 简单案例
第一步先引用 scriptManager <asp:UpdatePanel ID="UpdatePanelGuanZhu" runat="server"& ...
- 读书笔记之:C++ Primer (第4版)及习题(ch01-ch11) [++++]
读书笔记之:C++ Primer (第4版)及习题(ch01-ch11) [++++] 第2章 数据和基本类型 1. 整型 2. 习题:左值和右值 3. C++关键字/保留字和操作符替代值 4. 声明 ...
- (转)淘淘商城系列——Solr集群搭建
http://blog.csdn.net/yerenyuan_pku/article/details/72957201 我们之前做的搜索使用的是Solr的单机版来实现的,正是由于我们现在商品数据量不多 ...
- dispatch_sync
dispatch_sync does two things: queue a block blocks the current thread until the block has finished ...
- 完全掌握vuex
公司项目中大量的使用了vue,感觉对vue知识的掌握也越来越熟练了,录制视频教程也让我受益匪浅,自己成长的同时,我更希望帮助其他前端小伙伴一起成长.这篇文章我们主要讲解vuex. vuex是一个专门为 ...
- html第五节课
格式布局 一.position:fixed 锁定位置(相对于浏览器的位置),例如有些网站的右下角的弹出窗口. 示例: 二.position:absolute 1.外层没有position:absolu ...
- [CodeForces]1059C Sequence Transformation
构造题. 我递归构造的,发现如果N>3的话就优先删奇数,然后就把删完的提取一个公约数2,再重复操作即可. 具体原因我觉得是因为对于一个长度大于3的序列,2的倍数总是最多,要令字典序最大,所以就把 ...
- [Cerc2007]robotic sort
splay区间反转练手题 #include <iostream> #include <cstdio> #include <algorithm> using name ...