HDU 2256 Problem of Precision (矩阵乘法)
Problem of Precision
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 686 Accepted Submission(s): 386

1
2
5
97
841


#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int mod=; struct Matrix{
int arr[][];
}; Matrix unit,init; Matrix Mul(Matrix a,Matrix b){
Matrix c;
for(int i=;i<;i++)
for(int j=;j<;j++){
c.arr[i][j]=;
for(int k=;k<;k++)
c.arr[i][j]=(c.arr[i][j]+a.arr[i][k]*b.arr[k][j]%mod)%mod;
c.arr[i][j]%=mod;
}
return c;
} Matrix Pow(Matrix a,Matrix b,int k){
while(k){
if(k&){
b=Mul(b,a);
}
a=Mul(a,a);
k>>=;
}
return b;
} void Init(){
unit.arr[][]=, unit.arr[][]=, unit.arr[][]=unit.arr[][]=; init.arr[][]=init.arr[][]=, init.arr[][]=, init.arr[][]=;
} int main(){ //freopen("input.txt","r",stdin); int t,n;
Init();
scanf("%d",&t);
while(t--){
scanf("%d",&n);
Matrix res=Pow(init,unit,n-);
int ans=(*res.arr[][]-)%mod; //注意这里,刚开始这里没有%mod,WA了好几次
printf("%d\n",ans);
}
return ;
}
HDU 2256 Problem of Precision (矩阵乘法)的更多相关文章
- HDU 2256 Problem of Precision(矩阵)
Problem of Precision [题目链接]Problem of Precision [题目类型]矩阵 &题解: 参考:点这里 这题做的好玄啊,最后要添加一项,之后约等于,但是有do ...
- 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 ...
- HDU 2256 Problem of Precision (矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2256 最重要的是构建递推式,下面的图是盗来的.貌似这种叫共轭数. #include <iostr ...
- HDU 2256 Problem of Precision (矩阵快速幂)(推算)
Problem of Precision Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 2256 Problem of Precision
点击打开hdu 2256 思路: 矩阵快速幂 分析: 1 题目要求的是(sqrt(2)+sqrt(3))^2n %1024向下取整的值 3 这里很多人会直接认为结果等于(an+bn*sqrt(6))% ...
- hdu 2256 Problem of Precision 构造整数 + 矩阵快速幂
http://acm.hdu.edu.cn/showproblem.php?pid=2256 题意:给定 n 求解 ? 思路: , 令 , 那么 , 得: 得转移矩阵: 但是上面求出来的并 ...
- HDU 2256 Problem of Precision 数论矩阵快速幂
题目要求求出(√2+√3)2n的整数部分再mod 1024. (√2+√3)2n=(5+2√6)n 如果直接计算,用double存值,当n很大的时候,精度损失会变大,无法得到想要的结果. 我们发现(5 ...
- HDU 2256 Problem of Precision( 矩阵快速幂 )
链接:传送门 题意:求式子的值,并向下取整 思路: 然后使用矩阵快速幂进行求解 balabala:这道题主要是怎么将目标公式进行化简,化简到一个可以使用现有知识进行解决的一个过程!菜的扣脚...... ...
- HDU 5607 graph(DP+矩阵乘法)
[题目链接] http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=663&pid=1002 [题意] 给定一个有向 ...
随机推荐
- permission 权限 列表 6.0 运行时【案例】
demo地址:https://github.com/baiqiantao/PermissionTest.git <uses-permission android:name="andro ...
- 20个令人惊叹的音乐应用程序UI,值得收藏
我们无法想象世界上没有手机.他们已经成为日常生活中不可缺失的一部分.今天的手机可以让你不只是拨打电话和发送消息.它可以让你浏览网页空间,拍照,看书,听音乐等等. 回顾一下互联网,你会看到不同的音乐AP ...
- 编写和执行C#代码的插件:CS-Script for Notepad++
这个插件可以方便得让您在Notepad++编辑器中编辑和执行C#代码(脚本).它具备通用的C#智能感知和项目任务管理功能,方式非常类似于MS Visual Studio.除了这一点,它提供了通用的调试 ...
- GO语言基础之interface
接口interface 1. 接口是一个或多个方法签名的集合 2. 只要某个类型拥有该接口的所有方法签名,即算实现该接口,无需显示声明实现了哪个接口,这称为 Structural typing 3. ...
- 向第一个 p 元素添加一个类
This is a heading This is a paragraph. This is another paragraph. 向第一个 p 元素添加一个类 111 <html> &l ...
- [Algorithm] Tower Hopper Problem
By given an array of number, each number indicate the number of step you can move to next index: For ...
- [Node.js]30. Level 6: Listen 'Question' from client, and then Answer the Question
Clients can also answer each other questions, so let's build that feature by first listening for the ...
- shell命令xargs解析
1.多行变成单行 -bash-3.2# cat test.txt a b c d e f g o p q -bash-3.2# cat test.txt |xargs a b c d e f g o ...
- 圆形Camera预览实现
需求 最近有个需求要求界面上使用圆形相机预览进行面部检测 , 具体需求如下图 关于Camera之前接触得比较多 , 主要就是通过SurfaceView显示预览视图 , 因此需要展示圆形预览界面, 只需 ...
- Speculative Execution in Hadoop
来自:http://blog.csdn.net/macyang/article/details/7880671 所谓的推测执行,就是当所有task都开始运行之后,Job Tracker会统计所有任务的 ...