POJ 3070 矩阵mob
.
矩阵高速幂想法与快速幂相同
#include<iostream>
#include<cstdio>
#include<cstring>
#define MOD 10000
using namespace std;
struct matrix {
int mat[][];
matrix() { //构造函数与结构体同名 若写作init()函数 需调用
memset(mat,,sizeof(mat));
}
}; matrix mul(matrix A , matrix B) {
matrix C;
for(int i=;i<=;i++) {
for(int j=;j<=;j++) {
for(int k=;k<=;k++) {
C.mat[i][j]=(C.mat[i][j]+A.mat[i][k]*B.mat[k][j])%MOD;
}
}
}
return C;
} matrix powmul(matrix A ,int n) {
matrix B; //初始化为单位阵
B.mat[][]=;
B.mat[][]=;
while(n>=) {
if(n&) {
B=mul(B,A);
}
A=mul(A,A); //自身幂次
n/=;
}
return B;
} int main()
{ int n;
while(~scanf("%d",&n))
{
if(n==-) break;
matrix A;
A.mat[][]=A.mat[][]=A.mat[][]=;
A.mat[][]=;
A=powmul(A,n);
cout<<A.mat[][]<<endl;
} return ;
}
POJ 3070 矩阵mob的更多相关文章
- POJ ---3070 (矩阵乘法求Fibonacci 数列)
Fibonacci Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 ...
- POJ 3070 矩阵快速幂解决fib问题
矩阵快速幂:http://www.cnblogs.com/atmacmer/p/5184736.html 题目链接 #include<iostream> #include<cstdi ...
- 解题报告:poj 3070 - 矩阵快速幂简单应用
2017-09-13 19:22:01 writer:pprp 题意很简单,就是通过矩阵快速幂进行运算,得到斐波那契数列靠后的位数 . 这是原理,实现部分就是矩阵的快速幂,也就是二分来做 矩阵快速幂可 ...
- POJ 3070 矩阵快速幂
题意:求菲波那切数列的第n项. 分析:矩阵快速幂. 右边的矩阵为a0 ,a1,,, 然后求乘一次,就进一位,求第n项,就是矩阵的n次方后,再乘以b矩阵后的第一行的第一列. #include <c ...
- poj 3070 矩阵快速幂模板
题意:求fibonacci数列第n项 #include "iostream" #include "vector" #include "cstring& ...
- 矩阵快速幂 POJ 3070 Fibonacci
题目传送门 /* 矩阵快速幂:求第n项的Fibonacci数,转置矩阵都给出,套个模板就可以了.效率很高啊 */ #include <cstdio> #include <algori ...
- POJ 3070 Fibonacci(矩阵高速功率)
职务地址:POJ 3070 用这个题学会了用矩阵高速幂来高速求斐波那契数. 依据上个公式可知,第1行第2列和第2行第1列的数都是第n个斐波那契数.所以构造矩阵.求高速幂就可以. 代码例如以下: #in ...
- poj 3070 && nyoj 148 矩阵快速幂
poj 3070 && nyoj 148 矩阵快速幂 题目链接 poj: http://poj.org/problem?id=3070 nyoj: http://acm.nyist.n ...
- POJ 3070 + 51Nod 1242 大斐波那契数取余
POJ 3070 #include "iostream" #include "cstdio" using namespace std; class matrix ...
随机推荐
- <LeetCode OJ> 155. Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- Atitit.Java exe bat 作为windows系统服务程序运行
Atitit.Java exe bat 作为windows系统服务程序运行 1. 使用SC命令+srvany.exe (不错,推荐)+net start1 1.1. First 创建一个java的运 ...
- Java内存模型FAQ(一) 什么是内存模型
原文:http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html 第一章 译者:方腾飞 在多核系统中,处理器一般有一层或者多层的缓存,这 ...
- Redis用LPUSH和RPOP实现消息队列
using System; using System.Collections.Generic; using System.Linq; using System.Text; using ServiceS ...
- web.xml中url-pattern匹配规则
小知识 一般的URL组成 URL = 服务器地址 + RequestURI 例如URI:http://localhost:8080/practice/main [http://localhost:80 ...
- 从分类,排序,top-k多个方面对推荐算法稳定性的评价
介绍 论文名: "classification, ranking, and top-k stability of recommendation algorithms". 本文讲述比 ...
- Log4Net.Config配置信息《转》
看了log4net的简单使用之一_log4net介绍 大家对log4net组件应该有了大概的了解,下面再近一步介绍其在项目中如何应用. 1.Logger 所有的记录器都必须实现 ILog 接口,该接口 ...
- Cannot open channel to 3 at election address :3888 java.net.ConnectException: Connection refused (Connection refused)
关于Linux中搭建分布式时可能遇到的问题 这个问题来自于今天安装zookeeper时踩的一个大坑,害的我花了一天时间.在搭建zookeeper的分布式时,往往要进行这样的配置: server.1=h ...
- cocos2dx 3.0rc怎样创建项目
转自官网的文档. How to Run cpp-tests on win32 In this article, I will show you how to run cpp-tests on your ...
- Yii2实用基础学习笔记(二):Html助手和Request组件 [ 2.0 版本 ]
Html助手 1 .在@app\views\test的index.php中: <?php //引入命名空间 use yii\helpers\Html; ?> <?php //[一]表 ...