HDU 1757 A Simple Math Problem(矩阵快速幂模板)
题意:
题意很简单,不多说了。
思路:
|f(10) | |a0 a1 a2 ...a8 a9| |f(9)|
| f(9) | | 1 0 0 ... 0 0 | |f(8)|
| ..... | = | .. ... ... ... | | .. |
| f(2) | | 0 0 0 ... 0 0| |f(1)|
| f(1) | | 0 0 0 ... 1 0| |f(0)|
为自己留个模板。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = + ; int n,m; struct Matrix
{
int mat[][];
Matrix operator *(Matrix a)
{
Matrix c;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
c.mat[i][j]=;
for(int k=;k<;k++)
{
c.mat[i][j]+=(mat[i][k]*a.mat[k][j])%m;
c.mat[i][j]%=m;
}
}
}
return c;
}
}; Matrix base, ans; void init()
{
for(int i=;i<;i++)
for(int j=;j<;j++)
{
if(i==j) ans.mat[i][j]=;
else ans.mat[i][j]=;
if(i-==j) base.mat[i][j]=;
else base.mat[i][j]=;
}
} void pow(int n)
{
while(n)
{
if(n&) ans=ans*base;
base=base*base;
n>>=;
}
} int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d%d",&n,&m))
{
init();
for(int i=;i<;i++) scanf("%d",&base.mat[][i]);
if(n<) {printf("%d\n",n%m);continue;}
pow(n-);
int sum=;
for(int i=;i<;i++) sum=(sum+ans.mat[][i]*(-i))%m;
printf("%d\n",sum);
}
return ;
}
HDU 1757 A Simple Math Problem(矩阵快速幂模板)的更多相关文章
- HDU 1757 A Simple Math Problem (矩阵快速幂)
题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...
- hdu 1757 A Simple Math Problem_矩阵快速幂
题意:略 简单的矩阵快速幂就行了 #include <iostream> #include <cstdio> #include <cstring> using na ...
- HDU 1757 A Simple Math Problem(矩阵)
A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...
- HDU1757 A Simple Math Problem 矩阵快速幂
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 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 ...
- HDU 1757 A Simple Math Problem 【矩阵经典7 构造矩阵递推式】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (J ...
- hdu-1757 A Simple Math Problem---矩阵快速幂模板题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1757 题目大意: 求递推式第k项模m If x < 10 f(x) = x.If x > ...
- 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) + …… ...
- hdu 1757 A Simple Math Problem (矩阵快速幂)
Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 ...
- hdu 1757 A Simple Math Problem (矩阵快速幂,简单)
题目 也是和LightOJ 1096 和LightOJ 1065 差不多的简单题目. #include<stdio.h> #include<string.h> #include ...
随机推荐
- matplotlib —— 调整坐标轴
import matplotlib.pyplot as plt import numpy as np # 绘制普通图像 x = np.linspace(-1, 1, 50) y1 = 2 * x + ...
- html08
1.JQuery 是一个js框架一堆的 js文件 -形成 > 包 - 形成> 工具 - 形成> ->库 -> 框架 是一个轻量级的库 封装了js原生里js css dom ...
- html09
1.Jquery的常用方法1)选择器2)操作节点以下的 obj 都是指 jQuery对象 1.操作样式 obj.css() :不加参数是获取节点的css样式 obj.css({"属性&quo ...
- 用户用户组管理:用户管理命令useradd
添加玩用户后,其实改变的就是几个配置文件. 默认组一般设置成与用户名字,ID相同的.
- MacaW Baby Learns Computer
A - Macaw Baby Learns Computer Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & ...
- 无法在web服务器下启动调试。该Web服务器未及时响应
下午在运行项目的时候,突然出现了以下错误: 无法在web服务器上启动调试.该Web服务器未及时响应.可能是因为另一个调试器已连接到该Web服务器. 搜索了很久才找到这个解决方案: 1:Web.conf ...
- Centos7下PHP的卸载与安装nginx
Centos7下PHP的卸载与安装nginx CentOS上PHP完全卸载,想把PHP卸载干净,直接用yum的remove命令是不行的,需要查看有多少rpm包,然后按照依赖顺序逐一卸载. 1.首先查看 ...
- python3.4学习笔记(一) 基本语法 python3不向下兼容,有些语法跟python2.x不一样
python3.4学习笔记(一) 基本语法 python3不向下兼容,有些语法跟python2.x不一样,IDLE shell编辑器,快捷键:ALT+p,上一个历史输入内容,ALT+n 下一个历史输入 ...
- git必备命令
git status 查看git的状态git add <path>的形式把我们<path>添加到索引库中,<path>可以是文件也可以是目录.git add -u ...
- web前端----jQuery扩展(很重要!!)
1.jQuery扩展语法 把扩展的内容就可以写到xxxx.js文件了,在主文件中直接导入就行了. 用法1.$.xxx() $.extend({ "GDP": function () ...