HDU 2256 Problem of Precision( 矩阵快速幂 )
链接:传送门
题意:求式子的值,并向下取整
思路:

然后使用矩阵快速幂进行求解
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( 矩阵快速幂 )的更多相关文章
- HDU 2256 Problem of Precision (矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2256 最重要的是构建递推式,下面的图是盗来的.貌似这种叫共轭数. #include <iostr ...
- 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 [题目链接]Problem of Precision [题目类型]矩阵 &题解: 参考:点这里 这题做的好玄啊,最后要添加一项,之后约等于,但是有do ...
- hdu 5667 BestCoder Round #80 矩阵快速幂
Sequence Accepts: 59 Submissions: 650 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- 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 数论矩阵快速幂
题目要求求出(√2+√3)2n的整数部分再mod 1024. (√2+√3)2n=(5+2√6)n 如果直接计算,用double存值,当n很大的时候,精度损失会变大,无法得到想要的结果. 我们发现(5 ...
- HDU 2256Problem of Precision(矩阵快速幂)
题意 求$(\sqrt{2} + \sqrt{3})^{2n} \pmod {1024}$ $n \leqslant 10^9$ Sol 看到题解的第一感受:这玩意儿也能矩阵快速幂??? 是的,它能q ...
- hdu 2256 Problem of Precision
点击打开hdu 2256 思路: 矩阵快速幂 分析: 1 题目要求的是(sqrt(2)+sqrt(3))^2n %1024向下取整的值 3 这里很多人会直接认为结果等于(an+bn*sqrt(6))% ...
- 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 ...
随机推荐
- geohash:用字符串实现附近地点搜索
转自:http://blog.charlee.li/geohash-intro/ geohash:用字符串实现附近地点搜索 上回说到了用经纬度范围实现附近地点搜索.一些小型应用中这样做没问题,但在大型 ...
- 区分JAVA创建线程的几种方法
1. start()和run() 通过调用Thread类的start()方法来启动一个线程,这时此线程是处于就绪状态,并没有运行.然后 通过此Thread类调用方法run()来完成其运行操 ...
- [Libre 6282] 数列分块入门 6 (分块)
原题:传送门 code: //By Menteur_Hxy #include<cstdio> #include<iostream> #include<algorithm& ...
- LVM man帮助
> man lvm LVM(8) System Manager's Manual LVM(8) NAME lvm — LVM2 tools SYNOPSIS lvm [command|file] ...
- PatentTips - Controlling TSC offsets for multiple cores and threads
BACKGROUND Many processors include a time stamp count (TSC) counter which is typically implemented a ...
- [SharePoint][SharePoint Designer 入门经典]Chapter12 高级工作流
1.使用Visio2010创建工作流标志 2.使用Visio Graphic服务可视化一个运行的工作流 3.使用InfoPath2010修饰工作流表单 4.导出可重用的工作流
- Python Study (01) 之 特殊方法
Python深入:特殊方法和多范式 Python是一切皆对象,意思就是python的天生就是个"纯面向对象语言"呀. 但是!!! Python还是一个多范式语言(multi-par ...
- 【C++】通用单链表
在C++的学习中,採用模板类,而採用虚函数实现多态性.达到通用的目的.结点类数据域被改造为指针,而把数据放在一个抽象类中.由指针与之建立联系. 採用虚函数实现多态性,达到通用的目的.堆内存的分配与释放 ...
- [React Router] Create a ProtectedRoute Component in React Router (setState callback to force update)
In this lesson we'll create a protected route just for logged in users. We'll combine a Route with a ...
- jQuery的父,子,兄弟节点查找方法
以下罗列一下jQery下节点查找的方法: jQuery.parent(expr) 找父亲节点.能够传入expr进行过滤,比方$("span").parent()或者$(" ...