Problem of Precision

【题目链接】Problem of Precision

【题目类型】矩阵

&题解:

参考:点这里

这题做的好玄啊,最后要添加一项,之后约等于,但是有double的时候一定不能取余,还是要记住的

&代码:

#include <cstdio>
#include <iostream>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
using ll=long long;
const int maxn= 1e3 +9;
ll n,M=1024;
typedef vector<ll> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B)
{
mat C(A.size(),vec(B[0].size()));
for(int i=0;i<A.size();i++)
for(int k=0;k<B.size();k++)
for(int j=0;j<B[0].size();j++){
C[i][j]=(C[i][j]+A[i][k]*B[k][j])%M;
}
return C;
}
mat bin_pow(mat A,ll n)
{
mat B(A.size(),vec(A.size()));
for(int i=0;i<A.size();i++)
B[i][i]=1;
while(n>0){
if(n&1)
B=mul(B,A);
A=mul(A,A);
n>>=1;
}
return B;
}
mat A(2,vec(2));
ll fin[]={5,2};
void init()
{
A[0][0]=5,A[0][1]=12;
A[1][0]=2,A[1][1]=5;
}
int main()
{
// ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
freopen("E:1.txt","r",stdin);
int T;cin>>T;
while(T--){
init();
cin>>n;
//这块返回来的mat一定要赋值给A啊 不要忘了
A=bin_pow(A,n-1);
ll ans=0;
for(int i=0;i<2;i++){
ans=(ans+A[0][i]*fin[i])%M;
}
cout<<(2*ans-1)%M<<endl;
}
return 0;
}

HDU 2256 Problem of Precision(矩阵)的更多相关文章

  1. HDU 2256 Problem of Precision(矩阵高速幂)

    题目地址:HDU 2256 思路: (sqrt(2)+sqrt(3))^2*n=(5+2*sqrt(6))^n; 这时要注意到(5+2*sqrt(6))^n总能够表示成an+bn*sqrt(6); a ...

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2256 最重要的是构建递推式,下面的图是盗来的.貌似这种叫共轭数. #include <iostr ...

  3. HDU 2256 Problem of Precision (矩阵快速幂)(推算)

    Problem of Precision Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  4. HDU 2256 Problem of Precision (矩阵乘法)

    Problem of Precision Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. hdu 2256 Problem of Precision

    点击打开hdu 2256 思路: 矩阵快速幂 分析: 1 题目要求的是(sqrt(2)+sqrt(3))^2n %1024向下取整的值 3 这里很多人会直接认为结果等于(an+bn*sqrt(6))% ...

  6. hdu 2256 Problem of Precision 构造整数 + 矩阵快速幂

    http://acm.hdu.edu.cn/showproblem.php?pid=2256 题意:给定 n    求解   ? 思路: , 令  , 那么 , 得: 得转移矩阵: 但是上面求出来的并 ...

  7. HDU 2256 Problem of Precision 数论矩阵快速幂

    题目要求求出(√2+√3)2n的整数部分再mod 1024. (√2+√3)2n=(5+2√6)n 如果直接计算,用double存值,当n很大的时候,精度损失会变大,无法得到想要的结果. 我们发现(5 ...

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

    链接:传送门 题意:求式子的值,并向下取整 思路: 然后使用矩阵快速幂进行求解 balabala:这道题主要是怎么将目标公式进行化简,化简到一个可以使用现有知识进行解决的一个过程!菜的扣脚...... ...

  9. hdu 2256 好神奇的矩阵!

    这题自己一开始硬是不会处理√6 前面的系数,直到看了别人的博客后才知道是怎么解得,不多说,先付上一张图: 推出这个关系后,就很容易了. #include<cstdio> #include& ...

随机推荐

  1. 从一个点的长度是多少说起(Talking started from the length of a point on the real number line)

    From the perspective of analytical geometry, an interval is composed of infinitely many points, whil ...

  2. 自动化运维工具-pdsh工具安装配置及简单使用讲解

    1.先决条件: 安装pssh工具的主机针对远程主机需要配置免秘钥认证: ssh-keygen -t rsa ssh-copy-id [remotehost] 2.下载pssh工具安装介质: https ...

  3. Vue的自动化测试

    前言 为什么我们需要测试? 让产品可以快速迭代,同时还能保持高质量 -- 阮一峰 持续集成是什么? 对于一些相对稳定的系统级别页面,自动化测试在提高测试的效率的方面起到非常重要的作用.前端的自动化测试 ...

  4. iphone及ipad屏幕尺寸参考

    初代iPhone 2007年,初代iPhone发布,屏幕的宽高是 320 x 480 像素.下文也是按照宽度,高度的顺序排列.这个分辨率一直到iPhone 3GS也保持不变.那时编写iOS的App(应 ...

  5. 没有文件扩展js的脚本引擎

    没有文件扩展js的脚本引擎 没有文件扩展js的脚本引擎怎么解决_百度经验 https://jingyan.baidu.com/article/ff42efa93a7ad9c19e2202f0.html

  6. Chap5:操作文件和目录[The Linux Command Line]

    Wildcards Wildcard Meaning * Matches any characters ? Matches any single character [characters] Matc ...

  7. CSS盒子模型(简要了解)

    CSS中, Box Model叫盒子模型(或框模型),Box Model规定了元素框处理元素内容(element content).内边距(padding).边框(border) 和 外边距(marg ...

  8. linux学习:【第2篇】常用命令

    狂神声明 : 文章均为自己的学习笔记 , 转载一定注明出处 ; 编辑不易 , 防君子不防小人~共勉 ! linux学习:[第2篇]常用命令 基本命令 //打开终端: CentOS:在任何地方,右键-- ...

  9. 深度剖析fork()的原理及用法

    我们都知道通过fork()系统调用我们可以创建一个和当前进程印象一样的新进程.我们通常将新进程称为子进程,而当前进程称为父进程.而子进程继承了父进程的整个地址空间,其中包括了进程上下文,堆栈地址,内存 ...

  10. java 泛型的通配符和限定

    package cn.sasa.demo1; import java.util.ArrayList; import java.util.Collection; import java.util.Ite ...