计蒜客习题 蒜头君倒水

推出转移矩阵
( 1 − x y x 1 − y ) \begin{pmatrix} 1-x&y \\ x&1-y \end{pmatrix} (1xxy1y)
之后的就很显然了 倒了几次就是求转移矩阵的几次幂 然后乘上原矩阵 ( 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值