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 - ...
随机推荐
- 理解 B*tree index内部结构
转载请注明出处:http://write.blog.csdn.net/postedit/40589651 Oracle数据库里的B树索引就好象一棵倒长的树.它包括两种类型的数据块:一种是索引分支块,还 ...
- Ubuntu安装分区设置
我的Ubuntu 安装分区 /boot 200M / 2000M /home 6000M swap 1000M /boot分区,它包含了操作系统的内核和在启动系统过程中所 ...
- angularjs手动解析表达式($parse)
<!DOCTYPE html> <html lang="zh-CN" ng-app="app"> <head> <me ...
- 洛谷 P1412 经营与开发
/* 粘一下开始写的暴力吧 虽然没啥价值 */ #include<iostream> #include<cstdio> #include<cstring> #inc ...
- json数据获取
今天Pei讲了一个android获取json数据的方式吧 代码什么的没看懂,反正知道就是那么一回事,用AsyncTask线程来获取json数据,我也不知道这样说对不对 估计以后回过来看的时候会发现一大 ...
- php进程继续执行
虽然浏览器提示localhost 的服务器响应时间过长.但是进程在后台继续执行,数据库的条数在增加.
- TextView drawablePadding没有效果
1.当TextView 设置宽度设置为match_parent的时候 TextView drawablePadding没有效果 ,字设置了center位置,但是和左边的图片离开很远 2.当TextVi ...
- Warning: World-writable config file '/etc/my.cnf' is ignored
1. 问题描述: 重启mysql服务时出现以下信息: Warning: World-writable config file '/etc/my.cnf' is ignored 出现这种情况的原因是:m ...
- C#中结构的使用
//声明结构 结构与枚举区别,一个不用声明类型,一个要声明类型 public struct Person { //这里叫字段,做用也是存储内容,变量只可以存一个值,字段可以存多个值 //声明字段前最好 ...
- OpenStack JEOS 镜像
JEOS:Just Enough Operating System 维基百科地址:http://en.wikipedia.org/wiki/Just_enough_operating_system O ...