HDU 2256 Problem of Precision(矩阵)
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(矩阵)的更多相关文章
- 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 (矩阵乘法)
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 2256 好神奇的矩阵!
这题自己一开始硬是不会处理√6 前面的系数,直到看了别人的博客后才知道是怎么解得,不多说,先付上一张图: 推出这个关系后,就很容易了. #include<cstdio> #include& ...
随机推荐
- [No000013A]Windows WMIC命令使用详解(附实例)
第一次执行WMIC命令时,Windows首先要安装WMIC,然后显示出WMIC的命令行提示符.在WMIC命令行提示符上,命令以交互的方式执行 执行“wmic”命令启动WMIC命令行环境.这个命令可以在 ...
- NLP任务:给定一句话,找出这句话中你想要的关键词,包括起始结束索引
在实际的nlp实际任务中,你有一大堆的人工标注的关键词,来新的一句话,找出这句话中的关键词,以便你以后使用,那如何来做呢? 1)用到正则的 finditer()方法,返回你匹配的关键词的迭代对象,包含 ...
- iOS RSA非对称加密测试流程
非对称加密需要两把钥匙:公钥和秘钥. 单向加密:一般情况下服务器会持有秘钥和公钥,那该怎么使用呢?以注册场景为例,最初服务器持有公钥和密钥. 用户注册时不是直接发送用户名,密码,验证码等明文信息给服务 ...
- a buzzword to refer to modern Web technologies
https://html.spec.whatwg.org/multipage/introduction.html#is-this-html5? HTML Living Standard — Last ...
- MyEvent.SetEvent; // 同步信号置位
MyEvent.SetEvent; // 同步信号置位 TSimpleEvent.Create = TEvent.Create(nil, True, False, nil) ...
- 转:Spring系列之beanFactory与ApplicationContext
原文地址:Spring系列之beanFactory与ApplicationContext 一.BeanFactoryBeanFactory 是 Spring 的“心脏”.它就是 Spring IoC ...
- MAC终端TAB自动补全忽略大小写
打开终端,输入: nano .inputrc 在里面粘贴上以下语句: set completion-ignore-case onset show-all-if-ambiguous onTAB: men ...
- 洛谷P4151 最大XOR和路径 [WC2011] 线性基+图论
正解:线性基+图论 解题报告: 传送门 首先可以思考一下有意义的路径会是什么样子,,,那就一定是一条链+一些环 挺显然的因为一条路径原路返回有没有意义辣?所以一定是走一条链+一些环(当然也可以麻油环, ...
- mysql 操作sql语句 目录
mysql 操作sql语句 操作数据库 mysql 操作sql语句 操作数据表 mysql 操作sql语句 操作数据表中的内容/记录
- centos安装Django之三:安装python
这是centos安装Django系列第三篇,安装python.centos系统已经自带了python2.6,但是它被系统很多程序所依赖,不建议删除.我们可以使用以下命令来查看我们使用的Python版本 ...