算数学期望,每个人都可以分开来考虑。Xi表示第i个人跑到另外一边的次数。

Xi服从二项分布。概率的和是个二项式,(p+1-p)^T,把二项式展开,p的偶次项是留在原来那一边的概率。

可以用((a+b)^T+(a-b)^T)/2来算出偶次项之和。

也可以用矩阵快速幂。矩阵构造如下

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
//#include<bits/stdc++.h>
using namespace std; typedef double MType;
const int maxn = 1e5+; struct Person
{
double p;
char side;
int T;
void IN(){
scanf("%d %c %lf",&T,&side,&p);
}
void cal(MType &lft, MType &rgh){
double keep = (+pow(-*p,T))/;
if(side == 'L') lft = keep, rgh = -keep;
else lft = -keep, rgh = keep;
}
}P; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int N; scanf("%d",&N);
MType L = , R = , ans = ;
for(int i = ; i < N; i++){
P.IN();
MType l,r;
P.cal(l,r);
ans += L*l + R*r;
L = r;
R = l;
}
printf("%.12lf",ans);
return ;
}

快速幂

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
//#include<bits/stdc++.h>
using namespace std; const int MSIZE = , n = ;
typedef double MType;
struct Matrix
{
MType dat[MSIZE][MSIZE];
MType *operator [](int x){ return dat[x]; }
Matrix operator * (Matrix& B) {
Matrix re;
for(int i = ; i < n; i++){
for(int j = ; j < n; j++){
re[i][j] = ;
for(int k = ; k < n; k++){
re[i][j] += dat[i][k]*B[k][j];
}
}
}
return re;
}
Matrix operator ^ (int q){
Matrix Re, A = *this;
for(int i = ; i < n; i++){
for(int j = ; j < n; j++){
Re[i][j] = i == j?:;
}
}
while(q){
if(q&){
Re = Re * A;
}
A = A * A;
q >>= ;
}
return Re;
}
}; const int maxn = 1e5+;
struct Person
{
double p;
char side;
int T;
void IN(){
scanf("%d %c %lf",&T,&side,&p);
}
void cal(MType &lft, MType &rgh){
Matrix C;
C[][] = C[][] = -p;
C[][] = C[][] = p;
C = C^T;
if(side == 'L') lft = C[][], rgh = C[][];
else lft = C[][], rgh = C[][];
}
}P[maxn]; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int N; scanf("%d",&N);
for(int i = ; i < N; i++){
P[i].IN();
}
//sort(P,P+N);
MType L = , R = , ans = ;
for(int i = ; i < N; i++){
MType l,r;
P[i].cal(l,r);
ans += L*l + R*r;
L = r;
R = l;
}
printf("%.12lf",ans);
return ;
}

最新文章

  1. 51nod贪心算法入门-----完美字符串
  2. 如何写出优秀的研究论文 Chapter 1. How to Write an A+ Research Paper
  3. 【转】iOS开发——基本常识篇&amp;各种控件默认高度
  4. char *详细指针
  5. ASP.NET AJAX注册命名空间
  6. tomcat 安全文件夹(Java之负基础实战)
  7. Android基础_web通信2
  8. 在Windows上使用Let加密IIS
  9. debugfs
  10. 20155332 2016-2017-2 《Java程序设计》第6周学习总结
  11. profile,bashrc,.bash_profile,.bash_login,.profile,.bashrc,.bash_logout浅析&#160;Part&#160;2
  12. 图像检索:RGBHistogram+欧几里得距离|卡方距离
  13. hdu 5183 hash表
  14. webpack入门指南-step04
  15. MQTT协议笔记之订阅
  16. Unix系统编程()在文件特定偏移量处的IO:pread和pwrite
  17. Git 设置 SOCKS 代理
  18. python 路径练习
  19. uva 10648(简单dp)
  20. ngnix 403 forbidden的解决办法

热门文章

  1. window下安装composer步骤(linux待研究)
  2. 反射实现增删改查(DAO层)——修改数据
  3. 设计模式——懒汉式单例类PK饿汉式单例类
  4. 洛谷P1772 [ZJOI2006]物流运输
  5. day01笔记
  6. Ubuntu16.04双网卡绑定
  7. [Leetcode]006. ZigZag Conversion
  8. SQL Server 查看分区表(partition table)的分区范围(partition range)
  9. 二进制读取 jdbc
  10. 机器学习框架ML.NET学习笔记【1】基本概念与系列文章目录