HDOJ 4686 Arc of Dream 矩阵高速幂
矩阵高速幂:
依据关系够建矩阵 , 高速幂解决.

Arc of Dream
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 2164 Accepted Submission(s): 680

where
a0 = A0
ai = ai-1*AX+AY
b0 = B0
bi = bi-1*BX+BY
What is the value of AoD(N) modulo 1,000,000,007?
Each test case contains 7 nonnegative integers as follows:
N
A0 AX AY
B0 BX BY
N is no more than 1018, and all the other integers are no more than 2×109.
1
1 2 3
4 5 6
2
1 2 3
4 5 6
3
1 2 3
4 5 6
4
134
1902
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; typedef long long int LL; const LL mod=1000000007LL; struct Matrix
{
int x,y;
LL m[6][6];
Matrix() {x=y=5;memset(m,0,sizeof(m));}
void one()
{
for(int i=0;i<5;i++) m[i][i]=1LL;
}
void show()
{
cout<<x<<" * "<<y<<endl;
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
cout<<m[i][j]<<",";
cout<<endl;
}
}
}; Matrix Mul(Matrix& a,Matrix& b)
{
Matrix ret;
ret.x=a.x; ret.y=b.y;
for(int i=0;i<a.x;i++)
{
for(int j=0;j<b.y;j++)
{
LL temp=0;
for(int k=0;k<b.y;k++)
{
temp=(temp+(a.m[i][k]*b.m[k][j])%mod)%mod;
}
ret.m[i][j]=temp%mod;
}
}
return ret;
} Matrix quickPow(Matrix m,LL x)
{
Matrix e;
e.one();
while(x)
{
if(x&1LL) e=Mul(e,m);
m=Mul(m,m);
x/=2LL;
}
return e;
} LL n,A0,B0,AX,AY,BX,BY; Matrix init_matrix()
{
Matrix ret;
ret.m[0][0]=1;
ret.m[1][0]=AY; ret.m[1][1]=AX;
ret.m[2][0]=BY; ret.m[2][2]=BX;
ret.m[3][0]=(BY*AY)%mod; ret.m[3][1]=(AX*BY)%mod;
ret.m[3][2]=(BX*AY)%mod; ret.m[3][3]=(AX*BX)%mod;
ret.m[4][3]=1LL; ret.m[4][4]=1LL;
return ret;
} Matrix Beg()
{
Matrix beg;
beg.m[0][0]=1;
beg.m[1][0]=A0;
beg.m[2][0]=B0;
beg.m[3][0]=A0*B0%mod;
return beg;
} int main()
{
while(cin>>n)
{
cin>>A0>>AX>>AY>>B0>>BX>>BY;
A0=A0%mod; AX=AX%mod; AY=AY%mod;
B0=B0%mod; BX=BX%mod; BY=BY%mod;
Matrix m=init_matrix();
m=quickPow(m,n);
Matrix beg=Beg();
LL ans=0;
for(int i=0;i<5;i++)
ans=(ans+beg.m[i][0]*m.m[4][i]%mod)%mod;
cout<<ans<<endl;
}
return 0;
}
HDOJ 4686 Arc of Dream 矩阵高速幂的更多相关文章
- hdu 4686 Arc of Dream(矩阵快速幂)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 其中a0 = A0ai = ai-1*AX+AYb0 = B0bi = bi-1*BX+BY ...
- HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...
- HDU4686 Arc of Dream 矩阵快速幂
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- S - Arc of Dream 矩阵快速幂
An Arc of Dream is a curve defined by following function: where a 0 = A0 a i = a i-1*AX+AY b 0 = B0 ...
- hdu----(4686)Arc of Dream(矩阵快速幂)
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU4686——Arc of Dream矩阵快速幂
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4686 题目大意: 已知a0=A0, ai=Ax*ai-1+Ay; b0=B0, bi=Bx*bi-1 ...
- HDU 4686 Arc of Dream(矩阵)
Arc of Dream [题目链接]Arc of Dream [题目类型]矩阵 &题解: 这题你做的复杂与否很大取决于你建的矩阵是什么样的,膜一发kuangbin大神的矩阵: 还有几个坑点: ...
- HDU4686 Arc of Dream —— 矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-4686 Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memo ...
- HDOJ 5411 CRB and Puzzle 矩阵高速幂
直接构造矩阵,最上面一行加一排1.高速幂计算矩阵的m次方,统计第一行的和 CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory ...
随机推荐
- 【转 记录】python中的encode以及decode
字符串编码常用类型:utf-8,gb2312,cp936,gbk等. python中,我们使用decode()和encode()来进行解码和编码 在python中,使用unicode类型作为编码的基础 ...
- Digital Adjustment of DC-DC Converter Output Voltage in Portable Applications
http://pdfserv.maximintegrated.com/en/an/AN818.pdf http://www.maximintegrated.com/app-notes/index.mv ...
- QT 安装 4.8.7 on solaris 10
1. 下载 QT 4.8.7: http://download.qt.io/official_releases/qt/4.8/4.8.7/qt-everywhere-opensource-src-4 ...
- 浏览器数据库IndexedDB介绍
摘要 在移动端H5页面开发的时候,为了更好的提高用户体验,可以对不常变化的数据做浏览器端数据缓存,在用户打开页面的时候,首先加载本地的数据,然后异步请求服务端,更新数据.在移动端webview中,可以 ...
- Bootstrap 3之美01-下载并引入页面
本篇主要包括: ■ 下载Bootstrap 3■ Bootstrap 3引入页面 下载Bootstrap 3 →打开网站:http://getbootstrap.com/→点击屏幕中央位置的Down ...
- Python脚本报错AttributeError: 'module' object has no attribute 'maketrans'
出现此错误的原因:是此文件smtp02.py 所在的目录下有string.pyc 的文件存在,与python库里的string.pyc冲突造成无法确认编译所取的类库.
- OpenCL 获取Program信息
本程序生成一个OpenCL Program,然后获取Program的source,事实上它的source就是一个char[],能够打印出来. 然后我们把这些内容和原来文本的内容对照,看看是否是我们想要 ...
- 转: Go -- 单例
最近在学习Golang,想着可以就以前的知识做一些串通,加上了解到go语言也是面向对象编程语言之后.在最近的开发过程中,我碰到一个问题,要用go语言实现单例模式.本着“天下知识,同根同源”(我瞎掰的~ ...
- Spring Validation
Spring Validation模块用于表单数据验证配置,示例如下 依赖Jar包 <dependency> <groupId>javax.validation</gro ...
- libjson 编译和使用 - 1. 编译
以下转自:http://blog.csdn.net/laogong5i0/article/details/8212511 最近想用box2dEdit来编辑一下比较复杂的图形然后倒入到自己有游戏里,但b ...