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   |
然后就是快速矩阵...
  1. #define LOCAL
  2. #include<cstdio>
  3. #include<cstring>
  4. #define LL __int64
  5. using namespace std;
  6.  
  7. const LL mod=;
  8.  
  9. struct node
  10. {
  11. LL mat[][];
  12. void init(int v){
  13. for(int i=;i<;i++){
  14. for(int j=;j<;j++)
  15. if(i==j)
  16. mat[i][j]=v;
  17. else
  18. mat[i][j]=;
  19. }
  20. }
  21. };
  22.  
  23. LL AO,BO,AX,AY,BX,BY,n;
  24. node ans,cc;
  25.  
  26. void init(node &a)
  27. {
  28. a.mat[][]=a.mat[][]=(AX*BX)%mod;
  29. a.mat[][]=a.mat[][]=(AX*BY)%mod;
  30. a.mat[][]=a.mat[][]=(BX*AY)%mod;
  31. a.mat[][]=a.mat[][]=(AY*BY)%mod;
  32. a.mat[][]=a.mat[][]=a.mat[][]=a.mat[][]=;
  33. a.mat[][]=a.mat[][]=a.mat[][]=;
  34. a.mat[][]=a.mat[][]=a.mat[][]=a.mat[][]=;
  35. a.mat[][]=a.mat[][]=;
  36. a.mat[][]=AX;
  37. a.mat[][]=AY;
  38. a.mat[][]=BX;
  39. a.mat[][]=BY;
  40. }
  41.  
  42. void Matrix(node &a, node &b)
  43. {
  44. node c;
  45. c.init();
  46. for(int i=;i<;i++)
  47. {
  48. for(int j=;j<;j++)
  49. {
  50. for(int k=;k<;k++)
  51. {
  52. c.mat[i][j]=(c.mat[i][j]+a.mat[i][k]*b.mat[k][j])%mod;
  53. }
  54. }
  55. }
  56.  
  57. for(int i=;i<;i++)
  58. {
  59. for(int j=;j<;j++)
  60. {
  61. a.mat[i][j]=c.mat[i][j];
  62. }
  63. }
  64. }
  65.  
  66. void pow(node &a,LL w )
  67. {
  68. while(w>)
  69. {
  70. if(w&) Matrix(ans,a);
  71. w>>=1L;
  72. if(w==)break;
  73. Matrix(a,a);
  74. }
  75. }
  76.  
  77. int main()
  78. {
  79. LL sab;
  80. #ifdef LOCAL
  81. freopen("test.in","r",stdin);
  82. #endif
  83. while(scanf("%I64d",&n)!=EOF)
  84. {
  85. scanf("%I64d%I64d%I64d",&AO,&AX,&AY);
  86. scanf("%I64d%I64d%I64d",&BO,&BX,&BY);
  87. if(n==){
  88.  
  89. printf("0\n");
  90. continue;
  91. }
  92. AO%=mod;
  93. BO%=mod;
  94. AX%=mod;
  95. AY%=mod;
  96. BX%=mod;
  97. BY%=mod;
  98. ans.init();
  99. init(cc);
  100. pow(cc,n-);
  101.  
  102. sab=(AO*BO)%mod;
  103. LL res=(ans.mat[][]*sab)%mod+(ans.mat[][]*AO)%mod+(ans.mat[][]*BO)%mod+ans.mat[][]%mod+(AO*BO)%mod;
  104. printf("%I64d\n",res%mod);
  105. }
  106. return ;
  107. }

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. bootstrp水平表单格式

    1:form里添加类 "form-horizontal" 2:把标签和表单控件(input 等)放在一个带有类名 "form-group"的div里 3:标签可 ...

  2. git -C

    https://git-scm.com/docs/git -C <path> Run as if git was started in <path> instead of th ...

  3. 头文件为什么要加#ifndef #define #endif

    #ifndef 在头文件中的作用 在一个大的软件工程里面,可能会有多个文件同时包含一个头文件,当这些文件编译链接成一个可执行文件时 ,就会出现大量“重定义”的错误.在头文件中实用#ifndef #de ...

  4. windows下安装zabbix_agents_2.2.0

    下载与解压 下载zabbix_agents_2.2.0 http://www.zabbix.com/downloads/2.2.0/zabbix_agents_2.2.0.win.zip 解压到C盘下 ...

  5. vs无法打开项目的解决方案

    错误提示: “未找到与约束 ContractName Microsoft.Internal.VisualStudio.PlatformUI.ISolutionAttachedCollectionSer ...

  6. JS——时间日期控件

    原文:http://blog.sina.com.cn/s/blog_621768f30100qmfz.html 今天找到一个还不错的日历控件 下载地址:http://www.my97.net/dp/d ...

  7. windows下的Git简单入手

    现在再搞golang,用go get github.com/xxx 命令使需要git.提交新项目到github.com也要git,老东西了,呵呵现在也要学习一下. 下载windows版的git. ·准 ...

  8. Nginx简介及配置实用

    Nginx简介 Nginx是一个高性能的HTTP和反向代理服务器: 支持的操作系统众多,windows.linux. MacOS X: 可实现负载均衡: Rewrite功能强大: 电商架构大部分都采用 ...

  9. yii2-datepicker/datetimepicker插件使用

    datepicker: https://github.com/2amigos/yii2-date-picker-widget 通过composer安装: composer require 2amigo ...

  10. openstack 网卡

    桥接基本原理: 物理网卡eth0 br0(桥) tap0,tap1(tap是给vm使用的接口)