HDU 4686 Arc of Dream

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
a 0 = A0
a i = a i-1*AX+AY
b 0 = B0
b i = b i-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 10 18, and all the other integers are no more than 2×10 9.
 

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   |   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;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值