矩阵高速幂:

依据关系够建矩阵 , 高速幂解决.

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

Problem Description
An Arc of Dream is a curve defined by following function:




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?

 
Input
There are multiple test cases. Process to the End of File.

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.
 
Output
For each test case, output AoD(N) modulo 1,000,000,007.
 
Sample Input
1
1 2 3
4 5 6
2
1 2 3
4 5 6
3
1 2 3
4 5 6
 
Sample Output
4
134
1902
 
Author
Zejun Wu (watashi)
 
Source
 

#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 矩阵高速幂的更多相关文章

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

  2. HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...

  3. HDU4686 Arc of Dream 矩阵快速幂

    Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

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

  5. hdu----(4686)Arc of Dream(矩阵快速幂)

    Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

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

  7. HDU 4686 Arc of Dream(矩阵)

    Arc of Dream [题目链接]Arc of Dream [题目类型]矩阵 &题解: 这题你做的复杂与否很大取决于你建的矩阵是什么样的,膜一发kuangbin大神的矩阵: 还有几个坑点: ...

  8. HDU4686 Arc of Dream —— 矩阵快速幂

    题目链接:https://vjudge.net/problem/HDU-4686 Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memo ...

  9. HDOJ 5411 CRB and Puzzle 矩阵高速幂

    直接构造矩阵,最上面一行加一排1.高速幂计算矩阵的m次方,统计第一行的和 CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory ...

随机推荐

  1. c#开发地磅称重软件

    2012年时即做过一个地磅称重软件,最近公司又接了一个地磅过磅软件的项目,把遇到的问题总结一下以备后用. 1.接线问题 因为客户方原来单独使用仪表,仪表未有接线和电脑连接,为此颇费周折才做好了接线.接 ...

  2. OLEDB Excel 与C# 的数据流通方法

    一.             名词解释: OleDbCommand 是对数据源执行各种操作的SQL语句或者存储过程,连接access.excel等数据文件进行数据操作时候用到的,其实和sqlcomma ...

  3. java反射知识点总结

    一.java反射基础 1.1 什么叫java反射? 答:程序运行期间,动态的获取类的基本信息.比如:创建对象,调用类的方法,获得类的基本结构.这样给程序设计提供了很大的灵活性.个人总结就是:根据动态需 ...

  4. Apache2.2.16+PHP5.3.3+MySQL5.1.49的配置方法

    第一步:下载安装的文件 1. MySQL:下载地址mysql-5.1.49-win32.msi: 2. Apache: 下载地址httpd-2.2.16-win32-x86-openssl-0.9.8 ...

  5. Android网络请求之OkHttp框架

    首先声明权限 <uses-permission android:name="android.permission.INTERNET"/> 在build.gradle中加 ...

  6. CoreAudio实现录音播音和扬声器听筒模式的切换

    本例子使用Core Audio实现类似于微信的音频对讲功能,可以录音和播放并且实现了听筒模式和扬声器模式的切换.录音主要使用AVAudioRecorder类来实现录音功能,播放则使用AVAudioPl ...

  7. SpringMVC in IDEA开发实践

    按照上篇装过Tomcat之后. 本机本来装了IDEA和Maven. 参考以下这篇 https://my.oschina.net/gaussik/blog/385697 <使用IntelliJ I ...

  8. 第二章 Jackson属性名转换+属性忽略

    @Data @JsonIgnoreProperties(ignoreUnknown = true) public class MyRecord { private boolean succeed; p ...

  9. EF操作增删改查

    lianxiEntities db = new lianxiEntities();//上下文的入口 #region //EF Added //UserInfo user = new UserInfo( ...

  10. STM32串口的设置和库函数的介绍

    串口设置的一般步骤可以总结为如下几个: 1) 串口时钟使能, GPIO时钟使能  2) 串口复位 3)GPIO 端口模式设置 4) 串口参数初始化  5) 开启中断并且初始化 NVIC(如果需要开启中 ...