HDU 1757 A Simple Math Problem(矩阵快速幂)
题目链接
题意 :给你m和k, 让你求f(k)%m。如果k<10,f(k) = k,否则 f(k) = a0 * f(k-1) + a1 * f(k-2) + a2 * f(k-3) + …… + a9 * f(k-10);
思路 :先具体介绍一下矩阵快速幂吧,刚好刚刚整理了网上的资料。可以先了解一下这个是干嘛的,怎么用。
这个怎么弄出来的我就不说了,直接看链接吧,这实在不是我强项,点这儿,这儿也行
1 //HDU 1757 2 #include <iostream> 3 #include <stdio.h> 4 5 using namespace std; 6 7 struct matrix 8 { 9 int m[10][10] ; 10 } b,tp,res,init ; 11 12 int n,m ; 13 14 matrix Mul(matrix a,matrix b) 15 { 16 matrix c ; 17 for(int i = 0 ; i < 10 ; i++) 18 { 19 for(int j = 0 ; j < 10 ; j++) 20 { 21 c.m[i][j] = 0 ; 22 for(int k = 0 ; k < 10 ; k++) 23 { 24 c.m[i][j] += (a.m[i][k] * b.m[k][j]) % m ; 25 c.m[i][j] %= m ; 26 } 27 } 28 } 29 return c ; 30 } 31 32 matrix matrix_mi(matrix p,int k) 33 { 34 matrix t = res; 35 for(int i = 0 ; i <= 10 ; i++) t.m[i][i] = 1 ; 36 while(k) 37 { 38 if(k & 1) 39 t = Mul(t,p) ; 40 k >>= 1 ; 41 p = Mul(p,p) ; 42 } 43 return t ; 44 } 45 46 void Init() 47 { 48 for(int i = 0 ; i < 10 ; i++) 49 for(int j = 0 ; j < 10 ; j++) 50 if(i-1 == j) 51 init.m[i][j]=1; 52 else 53 init.m[i][j]=0; 54 } 55 int main() 56 { 57 Init() ; 58 while(~scanf("%d %d",&n,&m)) 59 { 60 b = init ; 61 for(int i = 0 ; i < 10 ; i++) 62 scanf("%d",&b.m[0][i]) ; 63 for(int i = 0 ; i < 10 ; i++) 64 for(int j = 0 ; j < 10 ; j++) 65 if(i==j) 66 res.m[i][j] = 1 ; 67 else 68 res.m[i][j] = 0 ; 69 if(n >= 10) 70 { 71 int sum = 0 ; 72 tp = matrix_mi(b,n-9) ; 73 for(int i = 0 ; i < 10 ; i++) 74 sum += (tp.m[0][i] * (9-i))%m ; 75 printf("%d\n",sum%m) ; 76 } 77 else printf("%d\n",n%m) ; 78 } 79 return 0; 80 }
View Code
转载于:https://www.cnblogs.com/luyingfeng/p/3674431.html
HDU 1757 A Simple Math Problem(矩阵快速幂)相关推荐
- HDU 1757 A Simple Math Problem (矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757 在吴神的帮助下才明白如何构造矩阵,还是好弱啊. 此处盗一张图 1 #include <io ...
- HDU - 1757 A Simple Math Problem(矩阵快速幂,水题)
题目链接:点击查看 题目大意:实现公式: f(x)=x,x<10 f(x)=a0*f(x-1)+a1*f(x-2)+--+a9*f(x-10) 题目给出a0~a9,一个n和一个m,要求输出f(n ...
- 43行代码AC——HDU 1757 A Simple Math Problem(矩阵快速幂,附快速幂讲解)
一道经典的矩阵快速幂模板题. 传送门1-->快速幂基本思想 传送门2-->矩阵快速幂讲解(教主传授) 代码(去掉空行43行) #include<iostream> #inclu ...
- hdu 1757 A Simple Math Problem 构造矩阵
题意:函数f(x), 若 x < 10 f(x) = x. 若 x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + ...
- HDU 1757 A Simple Math Problem
Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x & ...
- HDU - 1757 A Simple Math Problem (矩阵快速幂)
Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 f(x) = a0 * ...
- HDOJ 1757 A Simple Math Problem(矩阵快速幂)
2018-5-24 简单的矩阵快速幂问题,重点是如何找到对应关系. f(10) a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 f(9) f(9) 1 0 0 0 0 0 0 0 0 0 ...
- A Simple Math Problem 矩阵打水题
A Simple Math Problem Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x ...
- HDU - 5974 A Simple Math Problem 题解
D - Simple Math Problem 戳上方进入原题哟~ 题目大意 给一个数 a,b. 让你求满足一下条件的 X,Y: X+Y = a LCM(X,Y) = b 解析 题目给出时间限制1s, ...
最新文章
- Asp.Net下的DataGrid的多层表头
- Java-JUC(一):volatile引入
- JMeter 压力測试使用函数和 CSV 文件參数化 json 数据
- git add/commit/pull之间的关系
- TI AM335x Linux MUX hacking
- jquery Map转JSON
- esp分区创建 linux_善用EFI系统分区ESP
- 中兴计算机笔试题库,中兴计算机笔试
- Win10登陆界面卡住,进去后无法打开网络相关的设置,谷歌浏览器无法上网
- java实现短信验证码发送功能
- 疫情时代无接触AI人脸识别技术助力智慧工地迅猛发展
- access如何求平均单价_数据库 – MS Access:单个查询中的平均值和总计算量
- 玩转Safari:扩展插件说明
- [转载]三、二、一 …… Geronimo!,第 2 部分: 构建 Geronimo
- ptx760功能图解_摩托罗拉PTX760对讲机
- migo初始化库存 s4_【S4 MM】S4中继续使用MB系统事务代码
- 就业难,如何“解救”2022年的应届毕业生......
- Ubuntu下的图像编辑软件
- 经典推荐算法-协同过滤
- 亚马逊合规必备,一文解决跨境卖家关于VAT、欧代、商标的所有问题