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 ...
随机推荐
- 训练1-P
一个矩形的面积为S,已知该矩形的边长都是整数,求所有满足条件的矩形中,周长的最小值. 例如:S = 24,那么有{1 24} {2 12} {3 8} {4 6}这4种矩形,其中{4 6}的周长最小, ...
- CentOS 7下搭建高可用集群
一 .安装集群软件 必须软件pcs,pacemaker,corosync,fence-agents-all,如果需要配置相关服务,也要安装对应的软件. 二.配置防火墙1.禁止防火墙和selinux# ...
- Problem 14
Problem 14 # Problem_14.py """ The following iterative sequence is defined for the se ...
- Python - def 函数
1.def 函数 如果我们用代码实现了一个小功能,但想要在程序代码中重复使用,不能在代码中到处粘贴这些代码,因为这样做违反了软件工程中 DRY原则. Python 提供了 函数功能,可以将我们这部分功 ...
- 转-----------------------js window.open() 操作
<% if request("infoid")<>"" then set rs=conn.execute("select * fro ...
- poj1035Spell checker
暴力解决. 先把字典里的每一个单词的长度存起来.在查找的时候.就比較长度,在多一个少一个之间找, #include<stdio.h> #include<string.h> #i ...
- c13--数组
// // main.c // 进制查表法 // // Created by xiaomage on 15/6/10. // Copyright (c) 2015年 xiaomage. All rig ...
- IPK僵尸网络 看看其传播手法
转自:http://www.freebuf.com/vuls/154975.html 一.IPK僵尸网络概述 IPK僵尸家族是自2012年底就开始出现并长期持续活跃在境外的DDoS僵尸网络.2016年 ...
- netty结构
一.先纵览一下Netty,看看Netty都有哪些组件? 为了更好的理解和进一步深入Netty,我们先总体认识一下Netty用到的组件及它们在整个Netty架构中是怎么协调工作的.Netty应用中必不可 ...
- 通过QEMU-GuestAgent实现从外部注入写文件到KVM虚拟机内部
本文将以宿主上直接写文件到VM内部为例讲解为何要注入以及如何实现 tag: qemu-ga, qemu guest agent, kvm, guest-file-write, inject 小慢哥的原 ...