HDU 4686 Arc of Dream

来源:互联网 发布:工程造价软件广联达 编辑:程序博客网 时间:2024/06/05 15:07

Arc of Dream

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


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
11 2 34 5 621 2 34 5 631 2 34 5 6
 

Sample Output
41341902
 

Author
Zejun Wu (watashi)
 

Source
2013 Multi-University Training Contest 9
 

Recommend
zhuyuanchen520   |   We have carefully selected several similar problems for you:  6229 6228 6227 6226 6225 

题意很容易理解

计算An,Bn可以用矩阵快速幂,但是计算An*Bn不好直接用矩阵快速幂

先计算一下A1*B1

A1*B1=(A0*Ax+Ay)*(B0*Bx+By)=A0*B0*Bx*Ax+A0*Ax*By+B0*Bx*Ay+Ay*By;

根据这个就可以构造矩阵:

Ax        0         0          0  Ay           A0

0          Bx       0          0  By           B0

Ax*By  Bx*Ay  Ax*Bx  0  Ay*By  X  A0*B0

0          0         1          1  0              0

0          0         0          0  1              1


#pragma comment(linker,"/STACK:1024000000,1024000000")#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<stack>#include<queue>#include<deque>#include<set>#include<map>#include<cmath>#include<vector>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> PII;#define pi acos(-1.0)#define eps 1e-10#define pf printf#define sf scanf#define lson rt<<1,l,mi#define rson rt<<1|1,mi+1,r#define root 1,1,n#define et tree[rt]#define _s second#define _f first#define all(x) (x).begin,(x).end#define mem(i,a) memset(i,a,sizeof i)#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)#define mi ((l+r)>>1)#define sqr(x) ((x)*(x))const int inf=0x3f3f3f3f;const int mod=1e9+7;ll n,a0,b0,a1,a2,b1,b2,a,b,c,d,ans[6][6],p[6][6],e;void multi(ll a[][6],ll b[][6]){    ll c[6][6];    mem(c,0);    for1(i,5)        for1(j,5)            for1(k,5)                c[i][j]=(c[i][j]+a[i][k]*b[k][j])%mod;    for1(i,5)        for1(j,5)            a[i][j]=c[i][j];}void init(){    mem(ans,0);    for1(i,5)ans[i][i]=1;    mem(p,0);    p[1][1]=a1,p[1][5]=a2,p[2][2]=b1,p[2][5]=b2;    p[3][1]=a,p[3][2]=b,p[3][3]=c,p[3][5]=d;    p[4][3]=p[4][4]=p[5][5]=1;}void quick(ll x){    while(x)    {        if(x&1)multi(ans,p);        x>>=1;        multi(p,p);    }}int main(){    while(~sf("%I64d",&n))    {        sf("%I64d%I64d%I64d",&a0,&a1,&a2);        sf("%I64d%I64d%I64d",&b0,&b1,&b2);        a=a1*b2%mod;        b=b1*a2%mod;        c=a1*b1%mod;        d=a2*b2%mod;        e=a0*b0%mod;        init();        quick(n);        ll o=(ans[4][1]*a0%mod+ans[4][2]*b0%mod+ans[4][3]*e%mod+ans[4][5])%mod;        pf("%I64d\n",o);    }    return 0;}




原创粉丝点击