链接:传送门

题意:求式子的值,并向下取整

思路:

然后使用矩阵快速幂进行求解

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\n",(2*tmp.m[0][0]-1)%MOD);
}
return 0;
}

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

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

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

  2. 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 ...

  3. HDU 2256 Problem of Precision(矩阵)

    Problem of Precision [题目链接]Problem of Precision [题目类型]矩阵 &题解: 参考:点这里 这题做的好玄啊,最后要添加一项,之后约等于,但是有do ...

  4. hdu 5667 BestCoder Round #80 矩阵快速幂

    Sequence  Accepts: 59  Submissions: 650  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536 ...

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

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

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

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

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

    题意 求$(\sqrt{2} + \sqrt{3})^{2n} \pmod {1024}$ $n \leqslant 10^9$ Sol 看到题解的第一感受:这玩意儿也能矩阵快速幂??? 是的,它能q ...

  8. hdu 2256 Problem of Precision

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

  9. hdu 4686 Arc of Dream(矩阵快速幂)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 其中a0 = A0ai = ai-1*AX+AYb0 = B0bi = bi-1*BX+BY ...

随机推荐

  1. php设置cookie和删除cookie

    设置cookie Example : - set - <?php setcookie( "name", "value", "future_tim ...

  2. FansUnion:共同写博客计划终究还是“流产”了

    首先说说我原本的计划:我和周围的同学.朋友.好友 共同维护一个博客. 我对其他人并没有过高的期待.我一个人的写作量 = 其他人的写作量. 现实是,其他人没有怎么写. 对于,这个结果,我非常低无奈.谩骂 ...

  3. oracle 创建自增主键

    1.创建表 create table Test_Increase( userid number(10) NOT NULL primary key, /*主键,自动增加*/ username varch ...

  4. solrj 操作 solr 单机版

    一.导入 jar 包 <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr- ...

  5. 监控Oracle计数器

  6. jquery---- 数组根据值进行删除

    var chooseAttr = []; //serviceId为值 chooseAttr.splice($.inArray(serviceId,chooseAttr),);

  7. codevs——T1048 石子归并

     http://codevs.cn/problem/1048/  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Descriptio ...

  8. POJ 1948

    这道题我记得是携程比赛上的一道. 开始时想直接设面积,但发现不可以,改设能否构成三角形.设dp[i][j][k]为前i根木棍构成边长为j和k的三角形,那么转移可以为dp[i][j][k]=dp[i-1 ...

  9. 初学JavaScript之推測new操作符的原理

    本文是一篇原理推測的文章,假设有不准确的地方请指正, 原文:http://blog.csdn.net/softmanfly/article/details/34833931 JavaScript中构造 ...

  10. TCP打洞技术

    //转http://iamgyg.blog.163.com/blog/static/3822325720118202419740/ 建立穿越NAT设备的p2p的TCP连接仅仅比UDP复杂一点点,TCP ...