Arc of Dream

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

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
 
Author
Zejun Wu (watashi)
 
Source
 
这道题的分析,其实应该这样分析:
  我们看到这么个式子    然后我们知道ai=ai-1*AX+AY   ;     bi=bi-1*BX+BY;
   ai*bi =AXBX*ai-1*bi-1+AXBY*ai-1+BXAY*bi-1+AY*BY;
   对于这样一个式子,我们不妨构造这样一个矩阵......
如:
  |ai*bi|     |AX*BX , AXBY , BXAY , AYBY, 0  |^n-1   | ai-1*ai-1 |
  |  ai  |     |  0       , AX    , 0        , AY   , 0  |           |  ai-1       |
  |  bi  |  = |  0       , 0     ,   BX    , BY    , 0  |   *      |  bi-1       |
  |   1  |     |  0       , 0     ,  0       ,    1   , 0  |           |     1        |
  |  sn  |     | AXBX  , AXBY,  BXAY,  AYBY, 1 |            |     sn-1   |
然后就是快速矩阵...
 #define LOCAL
#include<cstdio>
#include<cstring>
#define LL __int64
using namespace std; const LL mod=; struct node
{
LL mat[][];
void init(int v){
for(int i=;i<;i++){
for(int j=;j<;j++)
if(i==j)
mat[i][j]=v;
else
mat[i][j]=;
}
}
}; LL AO,BO,AX,AY,BX,BY,n;
node ans,cc; void init(node &a)
{
a.mat[][]=a.mat[][]=(AX*BX)%mod;
a.mat[][]=a.mat[][]=(AX*BY)%mod;
a.mat[][]=a.mat[][]=(BX*AY)%mod;
a.mat[][]=a.mat[][]=(AY*BY)%mod;
a.mat[][]=a.mat[][]=a.mat[][]=a.mat[][]=;
a.mat[][]=a.mat[][]=a.mat[][]=;
a.mat[][]=a.mat[][]=a.mat[][]=a.mat[][]=;
a.mat[][]=a.mat[][]=;
a.mat[][]=AX;
a.mat[][]=AY;
a.mat[][]=BX;
a.mat[][]=BY;
} void Matrix(node &a, node &b)
{
node c;
c.init();
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
for(int k=;k<;k++)
{
c.mat[i][j]=(c.mat[i][j]+a.mat[i][k]*b.mat[k][j])%mod;
}
}
} for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
a.mat[i][j]=c.mat[i][j];
}
}
} void pow(node &a,LL w )
{
while(w>)
{
if(w&) Matrix(ans,a);
w>>=1L;
if(w==)break;
Matrix(a,a);
}
} int main()
{
LL sab;
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif
while(scanf("%I64d",&n)!=EOF)
{
scanf("%I64d%I64d%I64d",&AO,&AX,&AY);
scanf("%I64d%I64d%I64d",&BO,&BX,&BY);
if(n==){ printf("0\n");
continue;
}
AO%=mod;
BO%=mod;
AX%=mod;
AY%=mod;
BX%=mod;
BY%=mod;
ans.init();
init(cc);
pow(cc,n-); sab=(AO*BO)%mod;
LL res=(ans.mat[][]*sab)%mod+(ans.mat[][]*AO)%mod+(ans.mat[][]*BO)%mod+ans.mat[][]%mod+(AO*BO)%mod;
printf("%I64d\n",res%mod);
}
return ;
}

hdu----(4686)Arc of Dream(矩阵快速幂)的更多相关文章

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

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

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

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

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

  4. HDU4686 Arc of Dream 矩阵快速幂

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

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

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

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

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

  8. HDU 4686 Arc of Dream(矩阵)

    Arc of Dream [题目链接]Arc of Dream [题目类型]矩阵 &题解: 这题你做的复杂与否很大取决于你建的矩阵是什么样的,膜一发kuangbin大神的矩阵: 还有几个坑点: ...

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

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

随机推荐

  1. 【转载】OLE DB, ADO, ODBC关系与区别

    原文:OLE DB, ADO, ODBC关系与区别 OLE DB, ADO, ODBC 一. ODBC(Open Database Connectivity,开放数据库互连)是微软公司开放服务结构(W ...

  2. poj 1106 Transmitters (叉乘的应用)

    http://poj.org/problem?id=1106 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4488   A ...

  3. install Matlab2016b on Ubuntu 14.04

    From Download Download the install file from Download MATLAB, Simulink, Stateflow, and Other MathWor ...

  4. CXF WebService 开发文档

    参考资料: 1. http://cxf.apache.org/docs/ 2. http://www.cnblogs.com/hoojo/archive/2011/03/30/1999587.html ...

  5. [转载] goroutine背后的系统知识

    原文: http://www.sizeofvoid.net/goroutine-under-the-hood/ 文章写的非常好, 对内部原理解释的非常清楚, 是我喜欢的风格, 感谢作者的精彩文章. = ...

  6. Python学习(14)模块一

    目录 Python 模块 import语句 from ... import 语句 from ... import * 语句 定位模块 PYTHONPATH变量 命名空间和变量 dir()函数. glo ...

  7. Android linearlayout常用布局

    用linearlayout完成这样的布局效果,这样的布局还是比较常用的,具体的xml代码如下: <LinearLayout xmlns:android="http://schemas. ...

  8. iframe页面调用父窗口JS函数

    A页面iframe 页面B, 此时 如果要在B页面调用父页面A的函数 B页面写法 parent.functionName(); 错误1: 解决办法 var js_domain_async = 'bai ...

  9. 使用js加载器动态加载外部Javascript文件

    原文:http://www.cnblogs.com/xdp-gacl/p/3927417.html 今天在网上找到了一个可以动态加载js文件的js加载器,具体代码如下: JsLoader.js var ...

  10. Mysql的一些小知识点

    MySQL简介:是由瑞典的MySQL AB公司开发的,目前是Oracle(甲骨文)公司扥一个关系型数据库产品(2008年MySQL AB公司被Sun公司收购,2009年Sun公司又被 Oracle公司 ...