推出转移矩阵
(
1
−
x
y
x
1
−
y
)
\begin{pmatrix} 1-x&y \\ x&1-y \end{pmatrix}
(1−xxy1−y)
之后的就很显然了 倒了几次就是求转移矩阵的几次幂 然后乘上原矩阵
(
a
b
)
\begin{pmatrix} a\\ b \end{pmatrix}
(ab)即可
传送门
注意矩阵乘法不满足交换律
#include<bits/stdc++.h>
using namespace std;
double a,b;
double x,y;
int k;
struct mtx{double a[5][5];};
mtx mtx_mul(mtx a,mtx b){
mtx c;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
c.a[i][j]=0;
for(int k=0;k<2;k++)
c.a[i][j]+=a.a[i][k]*b.a[k][j];
}
}
return c;
}
mtx unit(){
mtx res;
for(int i=0;i<2;i++)
for(int j=0;j<2;j++){
i==j?res.a[i][j]=1:res.a[i][j]=0;
}
return res;
}
mtx init(){
mtx res;
res.a[0][0]=1.00-x;
res.a[1][0]=x;
res.a[0][1]=y;
res.a[1][1]=1.00-y;
return res;
}
mtx mtx_pow(mtx a,int k){
mtx res=unit(),t=a;
for(;k;k>>=1){
if(k&1) res=mtx_mul(res,t);
t=mtx_mul(t,t);
}
return res;
}
int main(){
mtx r;
cin>>r.a[0][0]>>r.a[1][0];
cin>>x>>y;
x/=100;y/=100;
cin>>k;
mtx t=init();
r=mtx_mul(mtx_pow(t,k),r);
printf("%.2lf %.2lf",r.a[0][0],r.a[1][0]);
return 0;
}