HDU 2256 Problem of Precision( 矩阵快速幂 )


链接:传送门

题意:求式子的值,并向下取整

思路:
o_hdu2256.jpg

然后使用矩阵快速幂进行求解

balabala:这道题主要是怎么将目标公式进行化简,化简到一个可以使用现有知识进行解决的一个过程!菜的扣脚...... 还是蒟蒻


/*************************************************************************
    > File Name: hdu2256.cpp
    > Author:    WArobot 
    > Blog:      http://www.cnblogs.com/WArobot/ 
    > Created Time: 2017年05月02日 星期二 23时41分58秒
 ************************************************************************/

#include<bits/stdc++.h>
using namespace std;

const int MOD = 1024;
const int maxn = 4;
#define ll long long
#define mod(x) ((x)%MOD)

struct mat{
    int m[maxn][maxn];
}unit;

mat operator *(mat a,mat b){
    mat ret;
    ll  x; 
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            x = 0;
            for(int k=0;k<2;k++)
                x += mod( a.m[i][k]*b.m[k][j] );
            ret.m[i][j] = x;
        }
    }
    return ret;
}
void init_unit(){
    for(int i=0;i<maxn;i++) unit.m[i][i] = 1;
}
mat pow_mat(mat a,ll x){
    mat ret = unit;
    while(x){
        if(x&1) ret = ret*a;
        a = a*a;
        x >>= 1;
    }
    return ret;
}
int main(){
    mat s,A;
    s.m[0][0] = 5;  s.m[0][1] = 0;  s.m[1][0] = 2;  s.m[1][1] = 0;
    A.m[0][0] = 5;  A.m[0][1] = 12; A.m[1][0] = 2;  A.m[1][1] = 5;
    init_unit();
    double tt = sqrt(6);
    ll t,n;
    cin>>t;
    while(t--){
        cin>>n;
        mat tmp = pow_mat(A,n-1);
        tmp = tmp*s;
        printf("%d\n",(2*tmp.m[0][0]-1)%MOD);
    }
    return 0;
}

转载于:https://www.cnblogs.com/WArobot/p/6803275.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值