• HDU 4686 Arc of Dream 矩阵快速幂


    若能根据关系 推出转移矩阵 就是简单题

    然而这需要多做题的经验

    ll Ax, Ay, A0, B0 ,Bx,By;
    
    struct Mat {
        ll m[5][5];
    };
    
    Mat E;
    
    Mat P;
    
    void init() {
        for (int i = 0; i < 5; i++) E.m[i][i] = 1;
        P.m[0][0] = 1ll;
        Ax %= MOD;
        Bx %= MOD;
        A0 %= MOD;
        B0 %= MOD;
        P.m[0][1] = (Ax * Bx)%MOD;
        P.m[0][2] = (By * Ax)%MOD;
        P.m[0][3] = (Ay * Bx)%MOD;
        P.m[0][4] = (Ay * By)%MOD;
        P.m[1][1] = (Ax * Bx)%MOD;
        P.m[1][2] = (By * Ax)%MOD;
        P.m[1][3] = (Ay * Bx)%MOD;
        P.m[1][4] = (Ay * By)%MOD;
        P.m[2][2] = Ax;
        P.m[2][4] = Ay;
        P.m[3][3] = Bx;
        P.m[3][4] = By;
        P.m[4][4] = 1ll;
    }
    
    Mat mul(const Mat& a, const Mat& b) {
        Mat c;
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                c.m[i][j] = 0;
                for (int k = 0; k < 5; k++) c.m[i][j] = (c.m[i][j] + (a.m[i][k] * b.m[k][j])%MOD)%MOD;
            }
        }
        return c;
    }
    
    Mat quickPower(Mat a, ll b) {
        Mat ans = E;
        Mat base = a;
        while (b) {
            if (b & 1) ans = mul(ans, base);
            base = mul(base, base);
            b >>= 1;
        }
        return ans;
    }
    
    int main() {
        ll n;
        while (~scanf("%lld%lld%lld%lld%lld%lld%lld", &n, &A0, &Ax, &Ay, &B0, &Bx, &By)) {
            init();
            ll res = (A0 * B0) % MOD;
            if (n == 0) {
                puts("0");
                continue;
            }
            if (n == 1) {
                printf("%lld
    ", res);
                continue;
            }
            Mat ans = quickPower(P, n - 1);
            res = (((ans.m[0][0] * res) % MOD + (ans.m[0][1] * res) % MOD)%MOD + (((A0 * ans.m[0][2]) % MOD + B0 * ans.m[0][3] % MOD)%MOD + 1ll * ans.m[0][4] % MOD)%MOD)%MOD;
            printf("%lld
    ", res);
        }
    }
  • 相关阅读:
    正则表达式(十四)——找出某一个网页内部的所有的邮箱
    正则表达式(十三)——分组
    正则表达式(十二)——字符串的替换
    正则表达式(十一)——find和lookingAt
    查看隐藏文件夹
    SpringBoot 热部署
    oracle dmp文件泵导入
    python -爬虫-pycrul安装问题
    阿里云https tomcat配置
    jar包下载
  • 原文地址:https://www.cnblogs.com/hznumqf/p/13230892.html
Copyright © 2020-2023  润新知