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): 309    Accepted Submission(s): 100


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

题意:求式子的值

题意:根据AoD(n+1)=AoD(n)+a(n)*b(n)

                    a(n+1)*b(n+1)=ax*bx*a(n)*b(n)+ax*by*a(n)+bx*ay*b(n)+ay*by

                    a(n+1)=ax*a(n)+ay

                    b(n+1)=bx*b(n)+by

 还有一个常数1 构造5*5阶的矩阵快速幂,就可以了....我才不会说hdu 竟然卡lld输入输出.....气死人了.....


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
const long long mod=1000000007;
long long n,a0,ax,ay,b0,bx,by;
struct point{
    long long a[6][6];
}res,e;
void init()
{
    int i;

    a0=a0%mod;  ax=ax%mod;  ay=ay%mod;
    b0=b0%mod;  bx=bx%mod;  by=by%mod;

    memset(res.a,0,sizeof(res.a));
    memset(e.a,0,sizeof(e.a));

    for(i=0;i<=5;i++) res.a[i][i]=1;
    e.a[1][1]=e.a[2][1]=e.a[5][5]=1;

    e.a[2][2]=ax*bx%mod;
    e.a[3][2]=ax*by%mod;
    e.a[4][2]=ay*bx%mod;
    e.a[5][2]=ay*by%mod;

    e.a[3][3]=ax%mod;
    e.a[5][3]=ay%mod;

    e.a[4][4]=bx%mod;
    e.a[5][4]=by%mod;
}
struct point mult(struct point x,struct point y)
{
    struct point temp;
    int i,j,k;

    for(i=1;i<=5;i++)
    {
        for(j=1;j<=5;j++)
        {
            temp.a[i][j]=0;
            for(k=1;k<=5;k++)
            {
                temp.a[i][j]=temp.a[i][j]+x.a[i][k]*y.a[k][j]%mod;
                if(temp.a[i][j]>=mod) temp.a[i][j]%=mod;
            }
        }
    }

    return temp;
}
void solve()
{
    while(n)
    {
        if(n&1ll) res=mult(res,e);
        e=mult(e,e);
        n=n>>1ll;
    }
}
void output()
{
    long long c[6],ans=0;
    int i;

    c[1]=0;
    c[2]=a0*b0%mod;
    c[3]=a0;
    c[4]=b0;
    c[5]=1;

    for(i=1;i<=5;i++) ans=(ans+c[i]*res.a[i][1]%mod)%mod;
    printf("%I64d\n",(ans+mod)%mod);
}
int main()
{
    while(scanf("%I64d",&n)>0)
    {
        scanf("%I64d%I64d%I64d",&a0,&ax,&ay);
        scanf("%I64d%I64d%I64d",&b0,&bx,&by);
        init();
        solve();
        output();
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值