HDU4686 Arc of Dream
来源:互联网 发布:预测大师软件 编辑:程序博客网 时间:2024/05/21 10:46
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
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?
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.
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: 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
- HDU4686 Arc of dream
- hdu4686 Arc of Dream
- HDU4686 Arc of Dream
- hdu4686---Arc of Dream(矩阵)
- HDU4686 Arc of Dream 矩阵快速幂
- 多校联合第九场1001HDU4686 Arc of Dream
- hdu4686 Arc of Dream ——构造矩阵+快速幂
- (矩阵快速幂)hdu4686 Arc of Dream
- HDU4686---Arc of Dream(矩阵快速幂,大数据的坑题)
- HDU Arc of Dream
- HDU 4686 Arc of Dream
- HDU 4686 Arc of Dream
- hdu 4686 Arc of Dream
- hdu 4686 Arc of Dream
- HDU 4686 Arc of Dream
- hdu-4686 Arc of Dream
- HDU 4686 Arc of Dream
- HDU 4686 Arc of Dream
- 黄聪:C#尽量使用接口来编程
- Scrollview 嵌套editext 解决滑动问题
- 技术大咖分享:如何评价一段代码?
- Idea2016 不能正常编译输出
- java中NIO编程另一种实现超实用
- HDU4686 Arc of Dream
- send()、sendto()和recv()、recvfrom()的使用
- Docker下kafka学习,三部曲之三:java开发
- Python中的lambda表达式
- php的错误级别
- Error:Execution failed for task ':app:processDebugResources'
- 粒子动画显示文字的Android控件
- 批处理获文件版本号
- SurfaceTexture BufferQueue has been abandoned