HDU4686 Arc of Dream

Arc of Dream

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


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:   6032  6031  6030  6029  6028 

不难想到矩阵快速幂,然后构造的矩阵。首先

1.ai*bi=(ai-1*AX+AY)*(bi-1*BX+BY)展开就知道需要的是什么了。

2.然后要计算的值sum=ai-1*bi-1+ai*bi。然后ai*bi可以又上面的式子得到。

#include <bits/stdc++.h>

using namespace std;
const int mod = 1e9+7;
long long n;
long long a0,ax,ay;
long long b0,bx,by;
struct matrix
{
    long long a[5][5];
    matrix operator * (const matrix & y)const
    {
        matrix ans= {0};
        for(int i=0; i<5; ++i)
            for(int j=0; j<5; ++j)
            {
                for(int k=0; k<5; ++k)ans.a[i][j]+=(a[i][k]*y.a[k][j])%mod;
                ans.a[i][j]%=mod;
            }
        return ans;
    }
};
long long getAns(long long n)
{
    matrix result = {1,0,0,0,0, 0,1,0,0,0, 0,0,1,0,0, 0,0,0,1,0, 0,0,0,0,1};
    matrix base = {1,0,0,0,0, (ax*bx)%mod,(ax*bx)%mod,0,0,0, (bx*ay)%mod,(bx*ay)%mod,bx,0,0, (ax*by)%mod,(ax*by)%mod,0,ax,0, (ay*by)%mod,(ay*by)%mod,by,ay,1};
    matrix ans= {(a0*b0)%mod,(a0*b0)%mod,b0,a0,1};
    while(n)
    {
        if(n&1ll)result=result*base;
        base=base*base;
        n>>=1ll;
    }
    return (ans*result).a[0][0];
}


int main()
{
    while(~scanf("%I64d",&n))
    {
        scanf("%I64d%I64d%I64d",&a0,&ax,&ay);
        scanf("%I64d%I64d%I64d",&b0,&bx,&by);
        if(!n)
        {
            puts("0");
        }
        else
        printf("%I64d\n",getAns(n-1));
    }
    return 0;
}







  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值