zoukankan      html  css  js  c++  java
  • 【HDU4686】Arc of Dream

    链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=46252

    傻逼矩阵加速。。QwQ

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define LL long long
    #define mod 1000000007
    using namespace std;
    LL n;
    int ax, ay, a0, bx, by, b0, qwq;
    struct Matrix{
        int s[5][5];
        void clear(){
            memset(s, 0, sizeof(s));
        }
    }ans, A;
    
    int mul(int a, int b){
    //    cout<<a<<" "<<b<<" "<<a*b%mod<<endl;
        return (int)((LL)((LL)a*(LL)b) % mod);
    }
    
    Matrix operator * (Matrix a, Matrix b){
        Matrix c;
        c.clear();
        for (int i = 0; i <= 4; i++){
            for (int j = 0; j <= 4; j++){
                for (int k = 0; k <= 4; k++){
                    c.s[i][j] = (c.s[i][j] + mul(a.s[i][k], b.s[k][j])) % mod;
                }
            }
        }
        return c;
    } 
    
    void Reset(){
        n--;
        ans.clear(); A.clear();
        ans.s[0][0] = 1; ans.s[0][1] = a0; ans.s[0][2] = b0; ans.s[0][3] = ans.s[0][4] = mul(a0, b0);
        A.s[0][0] = 1;
        A.s[0][1] = ay; A.s[1][1] = ax;
        A.s[0][2] = by; A.s[2][2] = bx;
        A.s[0][3] = A.s[0][4] = mul(ay, by);
        A.s[1][3] = A.s[1][4] = mul(ax, by);
        A.s[2][3] = A.s[2][4] = mul(bx, ay);
        A.s[3][3] = A.s[3][4] = mul(ax, bx);
        A.s[4][4] = 1;
        while (n){
            if (n&1) ans = ans * A;
            A = A * A;
            n >>= 1;
        }
    }
    
    int main(){
        while(~scanf("%lld", &n)){
            scanf("%d%d%d
    %d%d%d", &a0, &ax, &ay, &b0, &bx, &by);
            if (n == 0) { printf("0
    "); continue; }
            Reset();
            printf("%d
    ", ans.s[0][4]);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    【Android
    【数据结构】之链表(C语言描述)
    【数据结构】之顺序表(C语言描述)
    【Android
    【Android
    【Android
    【Android
    【Android
    在线HTTP速度测试(响应时间测试)及浏览器兼容测试
    阿里云 腾讯云 服务器挂载数据盘
  • 原文地址:https://www.cnblogs.com/Lukaluka/p/5406776.html
Copyright © 2011-2022 走看看