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

where
a0 = A0
ai = ai-*AX+AY
b0 = B0
bi = bi-*BX+BY
What is the value of AoD(N) modulo ,,,?
 
Input
There are multiple test cases. Process to the End of File.
Each test case contains nonnegative integers as follows:
N
A0 AX AY
B0 BX BY
N is no more than , and all the other integers are no more than ×.
Output
For each test case, output AoD(N) modulo ,,,.
 
Sample Input

 
Sample Output

 
Author
Zejun Wu (watashi)
 
Source
 

因为:a[i]*b[i]=(a[i-1]*AX+AY)*(b[i-1]*BX+BY)

      =(a[i-1]*b[i-1]*AX*BX+a[i-1]*AX*BY+b[i-1]*BX*AY+AY*BY)

构造矩阵:

                                                          |  1         0    0     0      0   |

                                                          |  AX*BY   AX   0     AX*BY    0   |

           {AoD(n-1),a[i-1],b[i-1],a[i-1]*b[i-1],1}*      |  BX*AY    0   BX    BX*AY    0   |      ={AoD(n),a[i],b[i],a[i]*b[i],1}

                                                          |  AX*BX    0   0      AX*BX   0   |

                                                          |  AY*BY   AY   BY    AY*BY    1   |

 

 

另外注意:

if(n==0){//这个判断条件很重要,没有就会超时
printf("0\n");
continue;
}

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 1000000
#define inf 1e12
ll n;
ll A0,Ax,Ay,B0,Bx,By;
struct Matrix{
ll mp[][];
};
Matrix Mul(Matrix a,Matrix b){
Matrix res;
for(ll i=;i<;i++){
for(ll j=;j<;j++){
res.mp[i][j]=;
for(ll k=;k<;k++){
res.mp[i][j]=(res.mp[i][j]+(a.mp[i][k]*b.mp[k][j])%MOD+MOD)%MOD;
}
}
}
return res;
}
Matrix fastm(Matrix a,ll b){
Matrix res;
memset(res.mp,,sizeof(res.mp));
for(ll i=;i<;i++){
res.mp[i][i]=;
}
while(b){
if(b&){
res=Mul(res,a);
}
a=Mul(a,a);
b>>=;
}
return res;
}
int main()
{
while(scanf("%I64d",&n)==){
scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&A0,&Ax,&Ay,&B0,&Bx,&By); if(n==){//这个判断条件很重要,没有就会超时
printf("0\n");
continue;
} ll a0=A0;
ll b0=B0; Matrix tmp;
memset(tmp.mp,,sizeof(tmp.mp));
tmp.mp[][]=%MOD;
tmp.mp[][]=Ax*By%MOD;
tmp.mp[][]=Ax%MOD;
tmp.mp[][]=Ax*By%MOD;
tmp.mp[][]=Bx*Ay%MOD;
tmp.mp[][]=Bx%MOD;
tmp.mp[][]=Bx*Ay%MOD;
tmp.mp[][]=Ax*Bx%MOD;
tmp.mp[][]=Ax*Bx%MOD;
tmp.mp[][]=Ay*By%MOD;
tmp.mp[][]=Ay%MOD;
tmp.mp[][]=By%MOD;
tmp.mp[][]=Ay*By%MOD;
tmp.mp[][]=%MOD; Matrix cnt=fastm(tmp,n-); Matrix g;
memset(g.mp,,sizeof(g.mp));
g.mp[][]=a0*b0%MOD;
g.mp[][]=a0%MOD;
g.mp[][]=b0%MOD;
g.mp[][]=a0*b0%MOD;
g.mp[][]=%MOD;
Matrix ans=Mul(g,cnt);
printf("%I64d\n",ans.mp[][]);
}
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. bzoj1645 [Usaco2007 Open]City Horizon 城市地平线

    Description Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at ...

  2. zoj3433(贪心+优先队列)

    Gu Jian Qi Tan Time Limit: 2 Seconds      Memory Limit: 65536 KB Gu Jian Qi Tan is a very hot Chines ...

  3. UML_活动图

    一.活动图的组成元素 Activity Diagram Element 1.活动状态图(Activity) 2.动作状态(Actions) 3.动作状态约束(Action Constraints) 4 ...

  4. knowledges address

    http://www.zhukun.net/archives/5794

  5. Multiple outputs from T4 made easy – revisited » DamienG

    Multiple outputs from T4 made easy – revisited » DamienG Multiple outputs from T4 made easy – revisi ...

  6. 代码中实际运用memcached——mycode

    1.下载安装64位memcached.exe  下载地址:http://blog.couchbase.com/memcached-windows-64-bit-pre-release-availabl ...

  7. 批处理Bat实现整合定时关机或取消定时关机

    @echo off :start choice /c:12 /m "输入1为设置定时关机,2为取消定时关机: " if errorlevel 2 goto cancel if er ...

  8. ThinkPHP框架搭建及常见问题(Apache或MySQL无法启动)----简单的初体验

    有一定基础的人勿进,这篇讲的只是零基础入门,都是我刚接触以及我所了解到的人刚开始有疑惑的地方,具体框架介绍会在后面的博客中介绍 这一篇只是为了一个简单的页面显示而介绍的方法,不涉及代码,开发环境,所以 ...

  9. ASP.NET和PHP全面对比

    谁是速度之王? 刚刚在9月编程语言排行榜上取得历史性突破的PHP在Web开发领域最到的对手可能就是基于微软.NET技术的ASP.NET.近日,微软的 Joe Stagner在博客上发表了一系列文章比较 ...

  10. codeforces #330 div2

    A: #include<cstdio> #include<algorithm> #include<cmath> #include<map> #inclu ...