zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    this指向
    call方法
    js浮点数的比较
    最近写h5 后台可配置大图轮播 发现pc上面正常,手机端无法显示
    记录好用的网站
    s-table组件设定
    iview TimePicker实现选择时间段
    symbol的使用
    JS笔记
    linux网络基础管理
  • 原文地址:https://www.cnblogs.com/WArobot/p/6803275.html
Copyright © 2011-2022 走看看