学了线代之后 终于明白了矩阵的乘法。。

于是 第一道矩阵快速幂。。

实在是太水了。。。

这差不多是个模板了

#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <iostream>
using namespace std; int N; struct matrix
{
int a[3][3];
}origin,res; matrix multiply(matrix x,matrix y)
{
matrix temp;
memset(temp.a,0,sizeof(temp.a));
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
for(int k=0;k<2;k++)
{
temp.a[i][j]+=(x.a[i][k]*y.a[k][j]%10000);
temp.a[i][j]%=10000;
}
}
}
return temp;
} void init()
{
memset(res.a,0,sizeof(res.a));
res.a[0][0]=res.a[1][1]=1;
res.a[1][0]=res.a[0][1]=0;
origin.a[0][0]=origin.a[0][1]=origin.a[1][0]=1;
origin.a[1][1]=0;
} void calc(int n)
{
while(n)
{
if(n&1)
res=multiply(res,origin);
n>>=1;
origin=multiply(origin,origin);
}
printf("%d\n",res.a[0][1]%10000);
} int main()
{
while(scanf("%d",&N)&&N!=-1)
{
init();
calc(N);
}
return 0;
}

poj3070 Fibonacci 矩阵快速幂的更多相关文章

  1. POJ3070:Fibonacci(矩阵快速幂模板题)

    http://poj.org/problem?id=3070 #include <iostream> #include <string.h> #include <stdl ...

  2. poj 3070 Fibonacci (矩阵快速幂乘/模板)

    题意:给你一个n,输出Fibonacci (n)%10000的结果 思路:裸矩阵快速幂乘,直接套模板 代码: #include <cstdio> #include <cstring& ...

  3. poj 3070 Fibonacci 矩阵快速幂

    Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. F ...

  4. HDU 1588 Gauss Fibonacci(矩阵快速幂)

    Gauss Fibonacci Time Limit: 3000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others) ...

  5. UVA - 10229 Modular Fibonacci 矩阵快速幂

                                 Modular Fibonacci The Fibonacci numbers (0, 1, 1, 2, 3, 5, 8, 13, 21, 3 ...

  6. POJ 3070 Fibonacci 矩阵快速幂模板

    Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18607   Accepted: 12920 Descr ...

  7. $loj$10222 佳佳的$Fibonacci$ 矩阵快速幂

    正解:矩阵快速幂 解题报告: 我永远喜欢loj! 一看到这个就应该能想到矩阵快速幂? 然后就考虑转移式,发现好像直接想不好想,,,主要的问题在于这个*$i$,就很不好搞$QAQ$ 其实不难想到,$\s ...

  8. POJ 3070 Fibonacci矩阵快速幂 --斐波那契

    题意: 求出斐波那契数列的第n项的后四位数字 思路:f[n]=f[n-1]+f[n-2]递推可得二阶行列式,求第n项则是这个矩阵的n次幂,所以有矩阵快速幂模板,二阶行列式相乘, sum[ i ] [ ...

  9. hdu 3306 Another kind of Fibonacci 矩阵快速幂

    参考了某大佬的 我们可以根据(s[n-2], a[n-1]^2, a[n-1]*a[n-2], a[n-2]^2) * A = (s[n-1], a[n]^2, a[n]*a[n-1], a[n-1] ...

随机推荐

  1. shell:监控进程运行状态并自动重启进程

    #!/bin/sh MAXRSTCOUNT=; PROCTOGO=/mnt/hgfs/code/test/show #count is the counter of test started time ...

  2. C++学习之虚继承

    http://blog.csdn.net/wangxingbao4227/article/details/6772579 C++中虚拟继承的概念 为了解决从不同途径继承来的同名的数据成员在内存中有不同 ...

  3. BZOJ 3675: [Apio2014]序列分割( dp + 斜率优化 )

    WA了一版... 切点确定的话, 顺序是不会影响结果的..所以可以dp dp(i, k) = max(dp(j, k-1) + (sumn - sumi) * (sumi - sumj)) 然后斜率优 ...

  4. (Problem 29)Distinct powers

    Consider all integer combinations ofabfor 2a5 and 2b5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, ...

  5. nginx的 CPU参数worker_processes和worker_cpu_affinity使用说明

    官方说明: http://wiki.nginx.org/NginxChsHttpMainModule#worker_cpu_affinity http://wiki.nginx.org/NginxCh ...

  6. dubbo 服务化

    当网站变大后,不可避免的需要拆分应用进行服务化,以提高开发效率,调优性能,节省关键竞争资源等. 当服务越来越多时,服务的URL地址信息就会爆炸式增长,配置管理变得非常困难,F5硬件负载均衡器的单点压力 ...

  7. iOS开发- 打包ipa,让别人设备安装你的App

    一般在接外包的时候, 通常第三方须要安装你的app进行測试(这时候你的app肯定是还没传到app store之前). 这样的情况下.假设是企业账号就好办了, 随便安装.. 可是个人开发人员账号呢? 假 ...

  8. 比赛--找丢失的数--解题报告T

    找丢失的数 题目大意: There is a permutation without two numbers in it, and now you know what numbers the perm ...

  9. 关于C++ 的eof

    #include<iostream> #include<fstream> #define MAXSIZE 1000 using namespace std; int main( ...

  10. [Swust OJ 541]--排列字典序问题

    题目链接:http://acm.swust.edu.cn/problem/0541/ Time limit(ms): 2000 Memory limit(kb): 65535 n个元素{1,2,... ...