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



    链接:传送门

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

    思路:

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

    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
    ",(2*tmp.m[0][0]-1)%MOD);
    	}
    	return 0;
    }
  • 相关阅读:
    jboss hello world
    jboss 7 启动问题
    jboss [how to access the admin console]
    tomee 消息持久化
    Python、C和Java对比
    编程语言产生时间表
    从关系型数据库到非关系型数据库
    约束和异常处理
    类与类之间的关系
    类的成员
  • 原文地址:https://www.cnblogs.com/WArobot/p/6803275.html
Copyright © 2020-2023  润新知