• hdu 1005 矩阵快速幂


    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    using namespace std;
    #define ll long long
    #define mod 1000000007
    #define inf 999999999
    //#pragma comment(linker, "/STACK:102400000,102400000")
    int scan()
    {
        int res = 0 , ch ;
        while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) )
        {
            if( ch == EOF ) return 1 << 30 ;
        }
        res = ch - '0' ;
        while( ( ch = getchar() ) >= '0' && ch <= '9' )
            res = res * 10 + ( ch - '0' ) ;
        return res ;
    }
    struct is
    {
        ll a[10][10];
    };
    is juzhenmul(is a,is b,ll hang ,ll lie)
    {
        int i,t,j;
        is ans;
        memset(ans.a,0,sizeof(ans.a));
        for(i=1;i<=hang;i++)
        for(t=1;t<=lie;t++)
        for(j=1;j<=lie;j++)
        {
            ans.a[i][t]+=(a.a[i][j]*b.a[j][t])%7;
        }
        return ans;
    }
    is quickpow(is ans,is a,ll x)
    {
        while(x)
        {
            if(x&1)  ans=juzhenmul(ans,a,2,2);
            a=juzhenmul(a,a,2,2);
            x>>=1;
        }
        return ans;
    }
    int main()
    {
        is ans,base;
        ll x,y,z,i,t;
        while(scanf("%lld%lld%lld",&x,&y,&z)!=EOF)
        {
            if(x==0&&y==0&&z==0)break;
            if(z<3)
            {printf("1
    ");
            continue;}
            memset(ans.a,0,sizeof(ans.a));
            ans.a[1][1]=1;
            ans.a[2][2]=1;
            //printf("%lld %lld
    %lld %lld
    ",ans.a[1][1],ans.a[1][2],ans.a[2][1],ans.a[2][2]);
            base.a[1][1]=x;
            base.a[1][2]=1;
            base.a[2][1]=y;
            base.a[2][2]=0;
            ans=quickpow(ans,base,z-2);
            printf("%lld
    ",(ans.a[1][1]+ans.a[2][1])%7);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    常用的字符集编码
    live555—VS2010/VS2013 下live555编译、使用及测试(转载)
    win32下Socket编程(转载)
    do{...}while(0)的意义和用法(转载)
    C++ static与单例模式
    MFC多线程各种线程用法 .
    a^1+b problem
    重返现世——题解
    第K大C
    懒癌
  • 原文地址:https://www.cnblogs.com/jhz033/p/5422291.html
Copyright © 2020-2023  润新知