点击打开hdu 2256

思路: 矩阵快速幂

分析:

1 题目要求的是(sqrt(2)+sqrt(3))^2n %1024向下取整的值

3 这里很多人会直接认为结果等于(an+bn*sqrt(6))%1024,但是这种结果是错的,因为这边涉及到了double,必然会有误差,所以根double有关的取模都是错误的思路

代码:

/************************************************
* By: chenguolin *
* Date: 2013-08-23 *
* Address: http://blog.csdn.net/chenguolinblog *
***********************************************/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; const int MOD = 1024;
const int N = 2; struct Matrix{
int mat[N][N];
Matrix operator*(const Matrix& m)const{
Matrix tmp;
for(int i = 0 ; i < N ; i++){
for(int j = 0 ; j < N ; j++){
tmp.mat[i][j] = 0;
for(int k = 0 ; k < N ; k++){
tmp.mat[i][j] += mat[i][k]*m.mat[k][j]%MOD;
tmp.mat[i][j] %= MOD;
}
}
}
return tmp;
}
}; int Pow(Matrix &m , int k){
if(k == 1)
return 9;
k--;
Matrix ans;
memset(ans.mat , 0 , sizeof(ans.mat));
for(int i = 0 ; i < N ; i++)
ans.mat[i][i] = 1;
while(k){
if(k&1)
ans = ans*m;
k >>= 1;
m = m*m;
}
int x = (ans.mat[0][0]*5+ans.mat[0][1]*2)%MOD;
return (2*x-1)%MOD;
} int main(){
int cas , n;
Matrix m;
scanf("%d" , &cas);
while(cas--){
scanf("%d" , &n);
m.mat[0][0] = 5 ; m.mat[1][1] = 5;
m.mat[1][0] = 2 ; m.mat[0][1] = 12;
printf("%d\n" , Pow(m , n));
}
}

hdu 2256 Problem of Precision的更多相关文章

  1. HDU 2256 Problem of Precision(矩阵)

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

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

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

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

  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 (矩阵快速幂)

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

  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 6343.Problem L. Graph Theory Homework-数学 (2018 Multi-University Training Contest 4 1012)

    6343.Problem L. Graph Theory Homework 官方题解: 一篇写的很好的博客: HDU 6343 - Problem L. Graph Theory Homework - ...

随机推荐

  1. atitit。浏览器缓存机制 and 微信浏览器防止缓存的设计 attilax 总结

    atitit.浏览器缓存机制 and 微信浏览器防止缓存的设计 attilax 总结 1. 缓存的一些机制 1 1.1. http 304 1 1.2. 浏览器刷新的处理机制 1 1.3. Expir ...

  2. iPhone 各版本屏幕分辨率

    参考:http://www.paintcodeapp.com/news/iphone-6-screens-demystified

  3. 95秀-自定义对话框 dialog 合集

    普通的确认对话框 NormalDialog.java import android.app.Dialog; import android.content.Context; import android ...

  4. 10-利用com组件读取office

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  5. css布局之负margin妙用及其他实现

    相信大家在项目的开发中都遇到过这样的需求,一行放X(X>1)个块且相邻块之间的间距相同. 大概就是上面这个样子,下面介绍几种实现的方式. 1.负margin大法 设置好元素的宽度和留白占满父级的 ...

  6. Java分页类 Page

    import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Iterator; ...

  7. ViewState探索

    什么是 view state? View State是客户端状态管理重要机制之一.当页面PostBack(向服务器发送或获得数据)时,它能存储页面的值.ASP.NET把View State属性作为页面 ...

  8. js获取当前日期时间同时显示星期

    JavaScript获取当前日期时间同时显示星期几,具体代码如下: <html> <head> <meta http-equiv="Content-Type&q ...

  9. location.href的用法

    *.location.href 用法: top.location.href=”url”          在顶层页面打开url(跳出框架) self.location.href=”url”       ...

  10. 智能SQL优化工具--SQL Optimizer for SQL Server(帮助提升数据库应用程序性能,最大程度地自动优化你的SQL语句 )

    SQL Optimizer for SQL Server 帮助提升数据库应用程序性能,最大程度地自动优化你的SQL语句 SQL Optimizer for SQL Server 让 SQL Serve ...