题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=4686

题目描述:

  题目上说的很清楚。

解题思路:

  就是递推,用快速幂+构造矩阵解决,因为n的取值范围好大,好全。

/*|1 0      0   0   0 ||1 ax*bx  0   0   0 ||0 ax*by  ax  0   0 |*|s[n] f[n] a[n] b[n] 1|=|s[n+1] f[n+1] a[n+1] b[n+1] 1||0 bx*ay  0   bx  0 ||0 by*ay  ay  by  1 |a[n+1]=a[n]*ax+ay;b[n+1]=b[n]*bx+by;f[n]=a[n]*b[n];s[n+1]=s[n]+f[n];
*/
 1 #include <iostream>
 2 #include <cstdlib>
 3 #include <cstdio>
 4 #include <algorithm>
 5 #include <vector>
 6 #include <queue>
 7 #include <cstring>
 8 using namespace std;
 9
10 const int maxn = 5;
11 #define LL long long
12 #define mod 1000000007
13 struct mat
14 {
15     LL p[maxn][maxn];
16 };
17
18 mat mul (mat a, mat b);
19 mat pow (LL n, mat a, mat b);
20 int main ()
21 {
22     LL n, a, ax, ay, b, bx, by;
23     mat A, B;
24     while (scanf ("%lld", &n) != EOF)
25     {
26         memset (A.p, 0, sizeof(A.p));
27         memset (B.p, 0, sizeof(B.p));
28         scanf ("%lld %lld %lld %lld %lld %lld", &a, &ax, &ay, &b, &bx, &by);
29         a %= mod, b %= mod, ax %= mod, bx %= mod, ay %= mod, by %= mod;
30         B.p[0][0] = 0;//贴这个代码,我什么也不想说明,只想表明矩阵相乘取余要全面,要细心,(wa哭了)
31         B.p[0][1] = a*b%mod;//心好累,在上面取完模还不够,在这里也要取模
32         A.p[1][1] = ax*bx%mod;
33         A.p[2][1] = ax*by%mod;
34         A.p[3][1] = ay*bx%mod;
35         A.p[4][1] = ay*by%mod;
36         B.p[0][2] = a;
37         B.p[0][3] = b;
38         B.p[0][4] = 1;
39         A.p[0][0] = A.p[1][0] = 1;
40
41         A.p[2][2] = ax;
42         A.p[3][3] = bx;
43         A.p[4][4] = 1;
44         A.p[4][2] = ay;
45         A.p[4][3] = by;
46         B = pow (n, A, B);
47         printf ("%lld\n", B.p[0][0]);
48     }
49     return 0;
50 }
51
52 mat mul (mat a, mat b)
53 {
54     int i, j, k;
55     mat c;
56     memset (c.p, 0, sizeof(c.p));
57
58     for (i=0; i<5; i++)
59         for (j=0; j<5; j++)
60         {
61             for (k=0; k<5; k++)
62                 c.p[i][j] = (c.p[i][j] + a.p[i][k] * b.p[k][j]) % mod;
63         }
64     return c;
65 }
66 mat pow (LL n, mat a, mat b)
67 {
68     while (n)
69     {
70         if (n % 2)
71         {
72             b = mul (b, a);
73         }
74         a = mul (a, a);
75         n /= 2;
76     }
77     return b;
78 }

转载于:https://www.cnblogs.com/alihenaixiao/p/4376302.html

hdu 4686 Arc of Dream相关推荐

  1. HDU 4686 Arc of Dream(递归矩阵加速)

    标题效果:你就是给你一程了两个递推公式公式,第一个让你找到n结果项目. 注意需要占用该公式的复发和再构造矩阵. Arc of Dream Time Limit: 2000/2000 MS (Java/ ...

  2. HDU - 4686 Arc of Dream(矩阵快速幂,水题)

    题目链接:点击查看 题目大意:给出定义: 现在依次给出n,A0,AX,AY,B0,BX,BY 求Aod的第n项对1e9+7取模后的结果 题目分析: 简单矩阵快速幂 首先化简一下: 初始矩阵:(取n=1 ...

  3. HDUOJ 4686 Arc of Dream

    HDUOJ 4686 Arc of Dream Problem Description An Arc of Dream is a curve defined by following function ...

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

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

  5. 线性代数二之矩阵加速DP——数学作业,Arc of Dream

    矩阵加速 数学作业 description solution code Arc of Dream description solution code 数学作业 description solution ...

  6. [矩阵乘法/快速幂专题]Arc of Dream,Recursive sequence,233 Matrix,Training little cats

    矩阵快速幂习题 复习矩阵乘法及快速幂模板 乘法模板 快速幂模板 T1:Arc of Dream 题目 题解 code T2:Recursive sequence 题目 题解 code T3:233 M ...

  7. hdu-4686 Arc of Dream

    http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意:已知a0,ax,ay  a[i] = ax * a[i-1] + ay; b0,bx,by    b ...

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

  9. 2013 Multi-University Training Contest 9 1011 Arc of Dream

    利用递推关系构建矩阵 然后矩阵快速幂 1 #include<cstdio> 2 #include<cstring> 3 typedef long long LL; 4 cons ...

最新文章

  1. SecureCRT的上传下载小技巧(Linux)
  2. Python中:re的match和search区别?
  3. 学校计算机数据采集处理系统,一种计算机数据采集处理分析系统的制作方法
  4. mysql sql len_MySQL的查询计划中ken_len的值计算方法
  5. unused import statement
  6. React的生命周期
  7. 离散数学反对称关系_离散数学课程总结(4)
  8. 从word得到表格数据插入数据库(6位行业代码)
  9. PAT 甲级 1002
  10. poi的excel解析工具类
  11. VB编程必备!_VB源码之友(内含-下载-破解-使用方法)
  12. 批量保存打开的网页到本地
  13. java开发文档怎么写?教你写java技术文档
  14. Roboware (ROS IDE)字体设置
  15. h264格式视频转mp4
  16. 中国移动和路由AP218刷机后桥接网络和配置无线打印教程
  17. GNSS精密轨道产品sp3与精密钟差产品clk批量下载(Linux Shell)
  18. karabiner json语法
  19. 通过Visual Studio 2019搭建DirectX 12开发环境
  20. 类脑计算机器人,机器人的类脑计算是什么?

热门文章

  1. java 通配符 类_关于类:具有多个类的Java泛型通配符
  2. JZOJ 5484. 【清华集训2017模拟11.26】快乐树
  3. docker 容器安装conposer_docker学习笔记(二)docker-composer
  4. 系统重装后 Endnote 不能和Word联用的解决方法
  5. echarts label加边框_关于echarts的lines中的label的设置 -问答-阿里云开发者社区-阿里云...
  6. python获取指定端口流量_利用python获取nginx服务的ip以及流量统计信息
  7. php 调用变量方法名,php中引用(变量和函数名前加符号)用法
  8. word 公式编号 右侧对齐_word排版实例:如何将文档中的公式与文字对齐
  9. 生产问题:一个线程罢工的诡异事件
  10. ansible-01