poj3070 Fibonacci 矩阵快速幂
学了线代之后 终于明白了矩阵的乘法。。
于是 第一道矩阵快速幂。。
实在是太水了。。。
这差不多是个模板了
#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 矩阵快速幂的更多相关文章
- POJ3070:Fibonacci(矩阵快速幂模板题)
http://poj.org/problem?id=3070 #include <iostream> #include <string.h> #include <stdl ...
- poj 3070 Fibonacci (矩阵快速幂乘/模板)
题意:给你一个n,输出Fibonacci (n)%10000的结果 思路:裸矩阵快速幂乘,直接套模板 代码: #include <cstdio> #include <cstring& ...
- poj 3070 Fibonacci 矩阵快速幂
Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. F ...
- HDU 1588 Gauss Fibonacci(矩阵快速幂)
Gauss Fibonacci Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- UVA - 10229 Modular Fibonacci 矩阵快速幂
Modular Fibonacci The Fibonacci numbers (0, 1, 1, 2, 3, 5, 8, 13, 21, 3 ...
- POJ 3070 Fibonacci 矩阵快速幂模板
Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18607 Accepted: 12920 Descr ...
- $loj$10222 佳佳的$Fibonacci$ 矩阵快速幂
正解:矩阵快速幂 解题报告: 我永远喜欢loj! 一看到这个就应该能想到矩阵快速幂? 然后就考虑转移式,发现好像直接想不好想,,,主要的问题在于这个*$i$,就很不好搞$QAQ$ 其实不难想到,$\s ...
- POJ 3070 Fibonacci矩阵快速幂 --斐波那契
题意: 求出斐波那契数列的第n项的后四位数字 思路:f[n]=f[n-1]+f[n-2]递推可得二阶行列式,求第n项则是这个矩阵的n次幂,所以有矩阵快速幂模板,二阶行列式相乘, sum[ i ] [ ...
- 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] ...
随机推荐
- lightOJ 1317 Throwing Balls into the Baskets
lightOJ 1317 Throwing Balls into the Baskets(期望) 解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/ ...
- 杭电ACM求平均成绩
求平均成绩 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- virtual host
<VirtualHost *:80> ServerAdmin webmaster@dummy-host.php100.com DocumentRoot "G:/w ...
- 在Github上搭建你的博客
title: blog on github date: 2014-03-24 20:29:47 tags: [blog,github,hexo] --- **用Github写博文** 参考http:/ ...
- Windows Phone 8初学者开发—第9部分:Windows Phone 8模拟器概述
原文 Windows Phone 8初学者开发—第9部分:Windows Phone 8模拟器概述 第9部分:Windows Phone 8模拟器概述 原文地址: http://channel9.ms ...
- Mac OS X10.9安装的Python2.7升级Python3.3步骤详解
Mac OS X10.9默认带了Python2.7,不过现在Python3.3.3出来了,如果想使用最新版本,赶紧升级下吧.基本步骤如下 第1步:官网下载Python3.3 这里面有windows和m ...
- 一道TOPK问题
今天遇到一道TOP k的变形题,题目大概意思是有10W个随机整数,然后对这些数进行如下操作: 1.当能被3整除时,将此数替换为此数和其它数两两相加的数,包括数本身 2.当不能被3整除时,将此数替换为原 ...
- lib32gcc1 : Depends: gcc-4.9-base (= 4.9-20140406-0ubuntu1) but 4.9.3-0ubuntu4
运行:sudo apt-get update 然后重新安装lib32gcc1
- Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0
今天在真机调试低版本系统的时候出现如题类似Layout Max Width在ios 8 之前不适用的问题, 初步估计是autolayout 所导致的 查找资料解决方法如下: 将label下Preffe ...
- ETHERNET帧结构
以太网帧http://blog.csdn.net/guoshaobei/article/details/4768514 Ethernet的帧格式 (转) http://jiangqiaosun.bl ...