Arc of Dream

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

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
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
 
题意:已知:
a0 = A0 b0 = B0
ai = ai-1*AX+AY
bi = bi-1*BX+BY
Sn = a0b0+a1*b1+...+a(n-1)*b(n-1);
求 Sn
 
题解:矩阵快速幂求n项和

a[i]*b[i] = (a[i-1]*Ax+Ay)(b[i-1]*Bx+By)
= Ax*Bx*a[i-1]*b[i-1]+Ay*Bx*b[i-1]+Ax*By*a[i-1]+Ay*By
s
[s[n-1],a[n-2]*b[n-2], b[n-2], a[n-2], 1]
A
[1 ,0 ,0 ,0 ,0]
[Ax*Bx ,Ax*Bx ,0 ,0 ,0]
[Ay*Bx ,Ay*Bx ,Bx ,0 ,0]
[Ax*By ,Ax*By ,0 ,Ax ,0]
[Ay*By ,Ay*By ,By ,Ay ,1]//n-1
s
[s[n], a[n-1]*b[n-1], b[n-1], a[n-1], 1]

 
#include<bits/stdc++.h>
#define N 5
#define mes(x) memset(x, 0, sizeof(x));
#define ll long long
const ll mod = 1e9+;
const int MAX = 0x7ffffff;
using namespace std;
struct mat {
ll a[N][N];
mat() {
memset(a, , sizeof(a));
}
mat operator * (mat b) {
mat c;
for (int i = ; i < N; i++)
for (int j = ; j < N; j++)
for (int k = ; k < N; k++)
c.a[i][j] = (c.a[i][j] + a[i][k] * b.a[k][j]) % mod;
return c;
}
};
mat f(mat b, ll m) {
mat c;
for (int i = ; i < N; i++)
c.a[i][i] = ;
while (m) {
if (m & )
c = c * b;
b = b * b;
m >>= ;
}
return c;
}
int main()
{
ll n, A0,Ax, Ay, Bx,By,B0;
mat A, s;
while(~scanf("%lld", &n)){
scanf("%lld%lld%lld%lld%lld%lld", &A0, &Ax, &Ay, &B0, &Bx, &By);
if(n == ){
printf("0\n");
continue;
}
mes(A.a);
mes(s.a);
s.a[][] = s.a[][] = (A0%mod*B0%mod)%mod;
s.a[][] = B0%mod;
s.a[][] = A0%mod;
s.a[][] = ;
A.a[][] = ;
A.a[][] = A.a[][] = (Ax%mod*Bx%mod)%mod;A.a[][] = Bx%mod;
A.a[][] = A.a[][] = (Ay%mod*Bx%mod)%mod;A.a[][] = Ax%mod;
A.a[][] = A.a[][] = (Ax%mod*By%mod)%mod;
A.a[][] = A.a[][] = (Ay%mod*By%mod)%mod;
A.a[][] = By;
A.a[][] = Ay;
A.a[][] = ;
A = f(A,n-);
s = s*A;
printf("%lld\n", (mod+s.a[][])%mod);
}
}
 

HDU4686 Arc of Dream 矩阵快速幂的更多相关文章

  1. HDU4686——Arc of Dream矩阵快速幂

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4686 题目大意: 已知a0=A0, ai=Ax*ai-1+Ay; b0=B0, bi=Bx*bi-1 ...

  2. HDU4686 Arc of Dream —— 矩阵快速幂

    题目链接:https://vjudge.net/problem/HDU-4686 Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memo ...

  3. hdu----(4686)Arc of Dream(矩阵快速幂)

    Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  4. S - Arc of Dream 矩阵快速幂

    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  ...

  5. hdu 4686 Arc of Dream(矩阵快速幂)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 其中a0 = A0ai = ai-1*AX+AYb0 = B0bi = bi-1*BX+BY ...

  6. HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...

  7. HDOJ 4686 Arc of Dream 矩阵高速幂

    矩阵高速幂: 依据关系够建矩阵 , 高速幂解决. Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/ ...

  8. HDU4686 Arc of Dream 矩阵

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - HDU4686 题意概括 a0 = A0 ai = ai-1*AX+AY b0 = B0 bi = bi-1* ...

  9. hdu 4686 Arc of Dream_矩阵快速幂

    题意:略 构造出矩阵就行了 |   AX   0    AXBY   AXBY       0  |                                                   ...

随机推荐

  1. 查看Linux服务器各种信息方法

    有的时候需要搜集服务器的各种信息,比如cpu信息,内存信息,linux版本信息,安装的各种软件信息等等.下面总结几种主要指标的查看方法. 1. 查看Linux发行版信息 [root@pcmweb ~] ...

  2. [转]IP动态切换脚本

    因为公司办公室要设置固定IP才行,而家里的IP段和公司是不一样的,家里采用了DHCP机制,这样每次就得改IP设置,很是不方便,就写了这个脚本来动态切换,很流畅的说!WINXP,WIN7测试通过~嘿嘿~ ...

  3. Microsoft.Jet.OLEDB.4.0和Microsoft.ACE.OLEDB.12.0的区别

    Microsoft.Jet.OLEDB.4.0和Microsoft.ACE.OLEDB.12.0的区别 时间 2012-12-19 20:30:12  CSDN博客原文  http://blog.cs ...

  4. 夺命雷公狗mongodb之----mongodb---1---的下载,安装,连接

    首先登录mongodb的官方网站即可进行下载: https://www.mongodb.com/download-center?jmp=nav#community 然后到wamp目录下创建一个mong ...

  5. 夺命雷公狗ThinkPHP项目之----企业网站16之文章列表页的完善(关联查询)

    我们栏目的所属栏目不能总是以数字来显示吧??这样的话,估计老板会让您直接卷铺盖滚蛋噢,嘻嘻... 所以我们需要对她进行关联查询,控制器代码如下所示: public function lists(){ ...

  6. [MaxOSX] 路由操作

    查看当前路由情况 netstat -nr 添加路由 sudo route -n add x.x.x.x/24 x.x.x.x 可以简单这样子理解: 第1个参数 x.x.x.x/24是远程地址 第2个参 ...

  7. 深入了解webservice_概念总结

    最近公司需要对java web端的第三方接口进行测试,使用WebService+TestNG实现,TsetNg是常用的自动化测试框架,这就不介绍了. WebService是一种跨编程语言和跨操作系统平 ...

  8. DB2 Unload 的时候遇到B37-04

    B37-04的问题是每个Mainframer首先会遇到的问题,在Unload的时候最大的可能性是Extend次数到16次了,这时候只要加大primary或secondary就可以了,我最常用的是pri ...

  9. hibernate笔记03

  10. UITableView(转)

    一.UITableView概述 UITableView继承自UIScrollView,可以表现为Plain和Grouped两种风格,分别如下图所示:          其中左边的是Plain风格的,右 ...