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 ...
随机推荐
- MAVEN 构建包的引用
1.什么叫构建包的引用? 当你存在两个maven项目分别是项目A,项目B时,且项目B要引用项目A的方法,那么你就用把项目A打成*.jar架包,放到本地的Maven仓库提供给项目B去引用. A.用命令到 ...
- 用Python图像处理
前几天弄了下django的图片上传,上传之后还需要做些简单的处理,python中PIL模块就是专门用来做这个事情的. 于是照葫芦画瓢做了几个常用图片操作,在这里记录下,以便备用. 这里有个字体文件,大 ...
- selenium+java处理鼠标悬停
1.元素比较明确(可视) 2.元素隐藏,需要鼠标移动到一定地方才显现(下图为某论坛列表,需要将鼠标移动到列表才显示操作按钮)
- (1)spring boot起步之Hello World【从零开始学Spring Boot】
Spring Boot交流平台 1.1 介绍 自从structs2出现上次的漏洞以后,对spring的关注度开始越来越浓. 以前spring开发需要配置一大堆的xml,后台spring加入了annot ...
- spring中的单例和多例
单例 对象在整个系统中只有一份,所有的请求都用一个对象来处理,如service和dao层的对象一般是单例的. 为什么使用单例:因为没有必要每个请求都新建一个对象的时候,浪费CPU和内存. 多例 对象在 ...
- [SharePoint2010开发入门经典]12、SPS2010安全管理
本章概要: 1.SPS中的用户授权 2.理解服务器场解决方案和沙箱解决方案的不同 3.理解表单验证和声明验证
- Grace Hopper 葛丽丝 霍普
Grace Murray Hopper(1906-1992), COBOL之母, Debug之母, A ship in port is safe, but that is not what ships ...
- __FUNCTION__, __LINE__ 有助于debug的宏定义
__FUNCTION__, __LINE__ 今天无意之间看到一段代码,里面有这样一个片段: if (!interface) { err ("%s - error, can't find d ...
- NAT配置
静态NAT Router(config)#ip nat inside source static tcp 192.168.100.2 61.159.62.131 指定地址转换映射 Router(c ...
- Fragment状态保存
这篇博文是对官方API Demo的FragmentRetainInstanceSupport.java的学习.路径在android-sdk-macosx/extras/android/support/ ...