zoukankan      html  css  js  c++  java
  • hdu 2256 好神奇的矩阵!

      这题自己一开始硬是不会处理√6 前面的系数,直到看了别人的博客后才知道是怎么解得,不多说,先付上一张图

      推出这个关系后,就很容易了。

     1 #include<cstdio>
     2 #include<cstring>
     3 typedef long long LL;
     4 const int mod= 1024;
     5 
     6 struct matrix{
     7     int a,b,c,d;
     8     matrix(int a=0, int b=0, int c=0, int d=0):a(a),b(b),c(c),d(d) {}
     9     matrix operator *(const matrix &m2){
    10         return matrix((a*m2.a%mod+b*m2.c%mod)%mod, (a*m2.b%mod+b*m2.d%mod)%mod, (c*m2.a%mod+d*m2.c%mod)%mod, (c*m2.b%mod+d*m2.d%mod)%mod);
    11     }
    12 } M(5,12,2,5),E(1,0,0,1);
    13 
    14 matrix quick_mod(matrix m, int b){
    15     matrix res(E);
    16     while(b){
    17         if(b&1)      res= res*m;
    18         m= m*m;
    19         b>>=1;
    20     }
    21     return res;
    22 }
    23 
    24 void solve(){
    25     int n;
    26     scanf("%d",&n);
    27     if(n==1) {    puts("9");    return ;    }
    28     matrix tmp= quick_mod(M,n-1);
    29     int xn= (tmp.a*5%mod+tmp.b*2%mod)%mod;
    30     printf("%d
    ",(2*xn-1)%mod);
    31 }
    32 
    33 int main(){
    34     int t;
    35     scanf("%d",&t);
    36     while(t--)    solve();
    37     return 0;
    38 }
  • 相关阅读:
    Java attack
    Java attack
    Java attack
    Java attack
    Java attack
    Java attack -Java 中的集合
    Java attack
    迟到的《Cashflow》游戏感悟
    三读《富爸爸穷爸爸》
    安装vue开发环境→安装淘宝镜像的时候报错
  • 原文地址:https://www.cnblogs.com/Newdawn/p/4132140.html
Copyright © 2011-2022 走看看