hdu 2256 Problem of Precision
思路: 矩阵快速幂
分析:
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的更多相关文章
- HDU 2256 Problem of Precision(矩阵)
Problem of Precision [题目链接]Problem of Precision [题目类型]矩阵 &题解: 参考:点这里 这题做的好玄啊,最后要添加一项,之后约等于,但是有do ...
- 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 思路: (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 (矩阵快速幂)(推算)
Problem of Precision Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 2256 Problem of Precision (矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2256 最重要的是构建递推式,下面的图是盗来的.貌似这种叫共轭数. #include <iostr ...
- 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 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 - ...
随机推荐
- diameter - degree problem
如今要构建一个网络模型,网络中的每一个节点最多和 d 个节点相连接, 且信息的传播从随意一个节点到另外随意一个节点的"最短路径" (路径依照单位路径算)都不能超过 k,问网络中最多 ...
- 使用MFC读写Excel
_Application m_ExlApp; //组件服务器的各个classes _Workbook m_ExlBook; Workbooks m_ExlBooks; _W ...
- Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)
遇着这个提示的话,如果本地只安装了一个mysql,这里写的很详细的 http://www.blogjava.net/asenyifei/articles/82575.html 看这里可以解决,如果本地 ...
- Python:代码调试的好帮手sys._getframe()
python 的调试,令人非常忧伤,通过将输出路径打印的方式,可以提高很大的方便性: import sys #coding=utf-8 def get_cur_info(): print sys._g ...
- iis7 发布mvc 遇到的HTTP错误 403.14-Forbidden Web 服务器被配置为不列出此目录的内容
iis 7上发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容 提示里面的解决方法是: 如果不希望启用目录浏览,请确保配置了默认文档并且该文件存在. 使用 II ...
- FineUI初学手册
女朋友鄙视我原创少... 1.下载 进入官方论坛:http://www.fineui.com/bbs/ 要用到下载源代码和空项目下载 http://fineui.codeplex.com/ http: ...
- 杀掉linux所有进程的命令
ps -ef|grep 'opt/*/tomcat_ssi'|grep -v "grep"|awk '{print $2}'|xargs kill -9
- Nginx环境下常见的开源项目重写汇总
我们做PHP开发的,作者寒冰我觉得大部分时候都在跟开源的系统打交道.比如:Discuz.PHPCMS.ecshop.wordpress等开源系统.一般我们都是在本地搭建测试环境,用的web服务器都是a ...
- 1.tomcat部署项目的几种方式和weblogic部署方式及一点通讯
第一种部署方式: 直接使用myeclipse 找到server服务 添加要部署的项目Add Deployment ,然后选中某个项目,首选Exploded Archive(development ...
- :after伪类+content内容生成经典应用举例
一.简单说说content内容生成 content内容生成就是通过content属性生成内容,content属性早在CSS2.1的时候就被引入了,可以使用:before以及:after伪元素生成内容. ...