zoukankan      html  css  js  c++  java
  • HDU1437+模拟

    枚举中间可能出现的天气

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<stdlib.h>
     4 const int maxn = 1005;
     5 double mat[ 5 ][ 5 ];
     6 
     7 void solve( int L,int R,int n ){
     8     double ans[ 5 ],tp[ 5 ];
     9     double res = 0;
    10     for( int i=1;i<=n;i++ ){
    11         if( i==1 ){
    12             ans[ 1 ] = mat[ L ][ 1 ];
    13             ans[ 2 ] = mat[ L ][ 2 ];
    14             ans[ 3 ] = mat[ L ][ 3 ];
    15             //printf("i = 1: %lf %lf %lf
    ",ans[1],ans[2],ans[3]);
    16             continue;
    17         }
    18         else if( i==n ){
    19             res = ans[ 1 ]*mat[ 1 ][ R ];
    20             res += ans[ 2 ]*mat[ 2 ][ R ];
    21             res += ans[ 3 ]*mat[ 3 ][ R ];
    22             continue;
    23         }
    24         else {
    25             tp[1] = ans[1],tp[2] = ans[2],tp[3] = ans[3];
    26             ans[ 1 ] = tp[ 1 ]*mat[ 1 ][ 1 ]+tp[ 2 ]*mat[ 2 ][ 1 ]+tp[ 3 ]*mat[ 3 ][ 1 ];
    27             ans[ 2 ] = tp[ 1 ]*mat[ 1 ][ 2 ]+tp[ 2 ]*mat[ 2 ][ 2 ]+tp[ 3 ]*mat[ 3 ][ 2 ];
    28             ans[ 3 ] = tp[ 1 ]*mat[ 1 ][ 3 ]+tp[ 2 ]*mat[ 2 ][ 3 ]+tp[ 3 ]*mat[ 3 ][ 3 ];
    29            // ans[1] = tp[1],ans[2] = tp[2],ans[3] = tp[3];
    30             //printf("i = %d: %lf %lf %lf
    ",i,ans[1],ans[2],ans[3]);
    31             continue;
    32         }
    33     }
    34     printf("%.3lf
    ",res);
    35 }
    36 
    37 int main(){
    38     //freopen("in.txt","r",stdin);
    39     int T;
    40     scanf("%d",&T);
    41     while( T-- ){
    42         for( int i=1;i<=3;i++ ){
    43             for( int j=1;j<=3;j++ ){
    44                 scanf("%lf",&mat[ i ][ j ]);
    45             }
    46         }
    47         int K;
    48         scanf("%d",&K);
    49         while( K-- ){
    50             int L,R,N;
    51             scanf("%d%d%d",&L,&R,&N);
    52             if( N==1 ){
    53                 printf("%.3lf
    ",mat[ L ][ R ]);
    54                 continue;
    55             }
    56             solve( L,R,N );
    57         }
    58     }
    59     return 0;
    60 }
    View Code
  • 相关阅读:
    最近写代码的风格,请帮忙分析下优缺点
    jQuery的回调管理机制(三)
    jQuery的回调管理机制(二)
    jQuery的回调管理机制
    iOS组件化
    iOS内存泄漏检测及分析
    iOS 路由
    iOS https抓包工作记录
    第二章 算法入门
    第一章 算法在计算中的作用
  • 原文地址:https://www.cnblogs.com/xxx0624/p/3433213.html
Copyright © 2011-2022 走看看