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. [No0000DF]C# ZipFileHelper ZIP类型操作,压缩解压 ZIP 类封装

    using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using Sys ...

  2. TensorRT使用解析器导入模型的过程

  3. Mac开发博客摘录

    https://blog.csdn.net/wangyouxiang/article/details/17855255 https://www.cocoacontrols.com/controls?p ...

  4. bilibili的直播第三方IJKMediaFramework.framework下载打包使用教程

    参考和引用的地址: http://www.code4app.com/thread-8941-1-1.html http://blog.csdn.net/cccallen/article/details ...

  5. Linux and Oracle常用目录详解

    目录详解 目录 内容 / 根目录,一切从这里开始 /bin 包含系统启动和运行所必需的二进制文件(程序) /boot 包含Linux内核.最初的RAM磁盘映像(系统启动时,驱动程序会用到),以及启动加 ...

  6. LeetCode 637 Average of Levels in Binary Tree 解题报告

    题目要求 Given a non-empty binary tree, return the average value of the nodes on each level in the form ...

  7. 《Mysql 字符集》

    一:什么是字符集呢? - 引用书中的例子:同样是大熊猫,在大陆叫熊猫,在台湾叫猫熊,在美国叫Panda,要到了非洲,可能都不知道叫啥(于是就乱码了). - 在例子之后引入字符集的概念:字符集就是指符号 ...

  8. 九九乘法表python3写入文件中

    写入文件代码如下: with open("e:\\test01.txt","w+",encoding="utf-8") as wq: for ...

  9. ext.js的mvc

    1.Ext.js的mvc开发模式 在ext.js4.0以后引入mvc开发模式,将js分成model-view-controller三层,使得大量js代码变得更加易于维护和重用,这就是ext.jsmvc ...

  10. 【雅思】【写作】【大作文】Discuss both views and give your own opinion

    •Discuss both views and give your own opinion •    • •Agree or disagree •Discuss both views •Report ...