Arc of Dream

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 419    Accepted Submission(s): 148

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
 
Recommend
zhuyuanchen520
 

http://www.cnblogs.com/liuxueyang/archive/2013/08/20/3270893.html

#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int mod=; struct Matrix{
long long arr[][];
}; Matrix init,unit;
long long n,a0,ax,ay,b0,bx,by; //注意用long long,否则会溢出 Matrix Mul(Matrix a,Matrix b){
Matrix c;
for(int i=;i<;i++)
for(int j=;j<;j++){
c.arr[i][j]=;
for(int k=;k<;k++)
c.arr[i][j]=(c.arr[i][j]+a.arr[i][k]*b.arr[k][j]%mod)%mod;
c.arr[i][j]%=mod;
}
return c;
} Matrix Pow(Matrix a,Matrix b,long long k){
while(k){
if(k&){
b=Mul(b,a);
}
a=Mul(a,a);
k>>=;
}
return b;
} void Init(){
for(int i=;i<;i++)
for(int j=;j<;j++){
init.arr[i][j]=;
unit.arr[i][j]=;
}
unit.arr[][]=, unit.arr[][]=a0%mod, unit.arr[][]=b0%mod, unit.arr[][]=a0*b0%mod,
unit.arr[][]=a0*b0%mod; init.arr[][]=, init.arr[][]=ay%mod, init.arr[][]=by%mod, init.arr[][]=ay*by%mod,
init.arr[][]=ay*by%mod, init.arr[][]=ax%mod, init.arr[][]=ax*by%mod, init.arr[][]=ax*by%mod,
init.arr[][]=bx%mod, init.arr[][]=ay*bx%mod, init.arr[][]=ay*bx%mod, init.arr[][]=ax*bx%mod,
init.arr[][]=ax*bx%mod, init.arr[][]=;
} int main(){ //freopen("input.txt","r",stdin); while(cin>>n){
//scanf("%d%d%d%d%d%d",&a0,&ax,&ay,&b0,&bx,&by);
cin>>a0>>ax>>ay>>b0>>bx>>by;
if(n==){
puts("");
continue;
}
Init();
Matrix ans=Pow(init,unit,n-);
cout<<ans.arr[][]<<endl;
}
return ;
}

HDU 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. hdu 4686 Arc of Dream_矩阵快速幂

    题意:略 构造出矩阵就行了 |   AX   0    AXBY   AXBY       0  |                                                   ...

  4. HDU4686 Arc of Dream 矩阵快速幂

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

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

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

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

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

  8. HDOJ 4686 Arc of Dream 矩阵高速幂

    矩阵高速幂: 依据关系够建矩阵 , 高速幂解决. Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/ ...

  9. HDU 4686 Arc of Dream(矩阵)

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

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

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

随机推荐

  1. 【洛谷P1080】国王游戏

    我们按照左右手数的乘积升序排序,就能使最多金币数最小了 为什么呢? 我们知道: 1)如果相邻的两个人交换位置,只会影响到这两个人的值,不会影响他人 2)假设相邻的两个人i, i + 1.设A[i] B ...

  2. nodejs:express 4.x

    最近学习express,最新的版本到了4.x,与之前的3.0版本相比,变化还是很大的.网上的教程很多都是基于3.0的,再编译一个例子的时候,吃了不少苦头.现总结一下express4.x的变化. 安装: ...

  3. 第35讲:List的map、flatMap、foreach、filter操作代码实战

    List类的高阶方法          val fmap = List( 1,2 ,3). map { _ + 1 } //List(2, 3, 4)    val fruit_rev2 = frui ...

  4. C++混合编程之idlcpp教程Python篇(2)

    在上一篇 C++混合编程之idlcpp教程(一) 中介绍了 idlcpp 工具的使用.现在对 idlcpp 所带的示例教程进行讲解,这里针对的 Python 语言的例子.首先看第一个示例程序 Pyth ...

  5. Entity Framework 4 数据事务操作

    利用数据库链接进行事务操作 var db = ConnectionHelper.GetConn(ConnectionType.Write);//获取上下文 var conn = db.Connecti ...

  6. VS中自定义代码高亮

    文章:http://www.cnblogs.com/aanbpsd/p/Viola_ide_glslEditor.html 帮助: 编辑扩展点: https://msdn.microsoft.com/ ...

  7. Python变量/运算符/函数/模块/string

    Python笔记(一) 1.变量类型 Python 有五个内置的简单类型:bool.int.long.float 和 complex.这些类型是不可变的,就是说整数对象一旦创建,其类型便不可更改. t ...

  8. Xamarin.Forms入门-使用 Xamarin.Forms 来创建跨平台的用户界面

    Xamarin.Forms 是一个跨平台的.基于原生控件的UI工具包,开发人员可以轻松的创建适用于 Android,iOS 以及 Windows Phone的用户界面.Xamarin.Forms 通过 ...

  9. paip.互联网产品要成功的要素

    paip.互联网产品要成功的要素 作者Attilax  艾龙,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blog.csdn.net/atti ...

  10. atitit.动态加载数据库配置in orm hibernate mybatis

    atitit.动态加载数据库配置in orm 1. 动态加载数据库配置的优点::: 1 1.1. 组合多个配置文件... 1 1.2. 连接多个数据库 1 2. 基本的流程:::getCfg内存对象, ...