HDU1437—模拟

简单的模拟题。

枚举中间可能出现的天气。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
const int maxn = 1005;
double mat[ 5 ][ 5 ];

void solve( int L,int R,int n ){
    double ans[ 5 ],tp[ 5 ];
    double res = 0;
    for( int i=1;i<=n;i++ ){
        if( i==1 ){
            ans[ 1 ] = mat[ L ][ 1 ];
            ans[ 2 ] = mat[ L ][ 2 ];
            ans[ 3 ] = mat[ L ][ 3 ];
            //printf("i = 1: %lf %lf %lf\n",ans[1],ans[2],ans[3]);
            continue;
        }
        else if( i==n ){
            res = ans[ 1 ]*mat[ 1 ][ R ];
            res += ans[ 2 ]*mat[ 2 ][ R ];
            res += ans[ 3 ]*mat[ 3 ][ R ];
            continue;
        }
        else {
            tp[1] = ans[1],tp[2] = ans[2],tp[3] = ans[3];
            ans[ 1 ] = tp[ 1 ]*mat[ 1 ][ 1 ]+tp[ 2 ]*mat[ 2 ][ 1 ]+tp[ 3 ]*mat[ 3 ][ 1 ];
            ans[ 2 ] = tp[ 1 ]*mat[ 1 ][ 2 ]+tp[ 2 ]*mat[ 2 ][ 2 ]+tp[ 3 ]*mat[ 3 ][ 2 ];
            ans[ 3 ] = tp[ 1 ]*mat[ 1 ][ 3 ]+tp[ 2 ]*mat[ 2 ][ 3 ]+tp[ 3 ]*mat[ 3 ][ 3 ];
           // ans[1] = tp[1],ans[2] = tp[2],ans[3] = tp[3];
            //printf("i = %d: %lf %lf %lf\n",i,ans[1],ans[2],ans[3]);
            continue;
        }
    }
    printf("%.3lf\n",res);
}

int main(){
    //freopen("in.txt","r",stdin);
    int T;
    scanf("%d",&T);
    while( T-- ){
        for( int i=1;i<=3;i++ ){
            for( int j=1;j<=3;j++ ){
                scanf("%lf",&mat[ i ][ j ]);
            }
        }
        int K;
        scanf("%d",&K);
        while( K-- ){
            int L,R,N;
            scanf("%d%d%d",&L,&R,&N);
            if( N==1 ){
                printf("%.3lf\n",mat[ L ][ R ]);
                continue;
            }
            solve( L,R,N );
        }
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值