题目

也是和LightOJ 1096 和LightOJ 1065 差不多的简单题目。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; int num,mod;
struct matrix
{
int a[][];
}; matrix multiply(matrix x,matrix y)//矩阵乘法
{
matrix temp;
for(int i=;i<num;i++)
{
for(int j=;j<num;j++)
{
int ans=;
for(int k=;k<num;k++)
{
ans+=((x.a[i][k]*y.a[k][j])%mod);
}
temp.a[i][j]=ans%mod;
}
}
return temp;
} matrix calc(matrix origin ,matrix answ,int n)//矩阵快速幂——answ*origin^n
{
while(n)
{
if(n%==)//原来比赛时一直是这里被我不小心改成了0,怪不得案例一直都过不了
answ=multiply(origin,answ);
origin=multiply(origin,origin);
n/=;
}
return answ;
} int main()
{
int n;
while(scanf("%d%d",&n,&mod)!=EOF)
{
matrix origin= {,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,};
matrix answ={,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,,
,,,,,,,,,};
num=;
for(int i=;i>=;i--)//要注意这里的a9~a0的输入顺序
scanf("%d",&origin.a[][i]); answ=calc(origin,answ,n-);
printf("%d\n",answ.a[][]%mod);
}
return ;
}

hdu 1757 A Simple Math Problem (矩阵快速幂,简单)的更多相关文章

  1. HDU 1757 A Simple Math Problem (矩阵快速幂)

    题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...

  2. hdu 1757 A Simple Math Problem_矩阵快速幂

    题意:略 简单的矩阵快速幂就行了 #include <iostream> #include <cstdio> #include <cstring> using na ...

  3. HDU 1757 A Simple Math Problem(矩阵)

    A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...

  4. HDU1757 A Simple Math Problem 矩阵快速幂

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. 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 ...

  6. 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 ...

  7. 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) + …… ...

  8. 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 ...

  9. HDU 1757 A Simple Math Problem( 矩阵快速幂 )

    <font color = red , size = '4'>下列图表转载自 efreet 链接:传送门 题意:给出递推关系,求 f(k) % m 的值, 思路: 因为 k<2 * ...

随机推荐

  1. 【leetcode】15. 3Sum

    题目描述: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find ...

  2. 杭电ACM2097--Sky数

    这题思路很简单,把10,12,16进制数都按位相加,然后进行比较即可. http://acm.hdu.edu.cn/showproblem.php?pid=2097 <span style=&q ...

  3. WFP: 读取XPS文件或将word、txt文件转化为XPS文件

    读取XPS格式文件或将doc,txt文件转化为XPS文件,效果图如下: 1.XAML页面代码: <Window x:Class="WpfWord.MainWindow"    ...

  4. 分享:linux下apache服务器的配置和管理

    linux下apache服务器的配置和管理. 一.两个重要目录: Apache有两个重要的目录:1.配置目录/etc/httpd/conf:2.文档目录/var/www: 二.两种配置模式: Apac ...

  5. IIS6下, web.config配置为targetFramework="4.0"时出404错误

    打开IIS管理器,在"Web 服务扩展" 中 将ASP.NET v4.0设置为允许就好了.这个选项默认是禁止的.

  6. oracle-linux下挂载"移动硬盘" NTFS类型

    环境: ORACLE-LINUX 5.7 全新移动硬盘(未使用过) 移动硬盘空间3T 在默认情况下,Linux系统不支持NTFS分区挂载 1.服务器: A服务器和B服务器为一套ORACLE-RAC,移 ...

  7. ios7.0结合storyborad实现页面跳转的总结

    折腾了一整天,本文总结一下ios7.0页面跳转有关的内容 storyboard的潜规则 我接触ios很晚,环境已经是xcode5+ios7,所以对以前的IOS开发模式并不了解.在网上查阅了很多资料,发 ...

  8. .net视图中日期格式化

    昨天在做一个功能,要在界面上按照规定的格式显示一个时间,如果直接在expression那里格式化的话(如下:) @Html.DisplayFor(c => Convert.ToDateTime( ...

  9. C#转换日期类型

    日期1999-5-31 11:20转换成 /Date(928120800000+0800)/ 其中928120800000实际上是一个1970 年 1 月 1 日 00:00:00至这个DateTim ...

  10. ECSHOP模糊分词搜索和商品列表关键字飘红功能

    ECSHOP联想下拉框 1.修改page_header.lbi模版文件,将搜索文本框修改为: <input name="keywords" type="text&q ...