S - Arc of Dream 矩阵快速幂
where
a 0 = A0
a i = a i-1*AX+AY
b 0 = B0
b i = b i-1*BX+BY
What is the value of AoD(N) modulo 1,000,000,007?
InputThere 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 10 18, and all the other integers are no more than 2×10 9.OutputFor 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
| AX 0 AXBY AXBY 0 |
| 0 BX AYBX AYBX 0 |
{a[i-1] b[i-1] a[i-1]*b[i-1] AoD[i-1] 1}* | 0 0 AXBX AXBX 0 | = {a[i] b[i] a[i]*b[i] AoD[i] 1}
| 0 0 0 1 0 |
| AY BY AYBY AYBY 1 |
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<string>
using namespace std;
typedef unsigned long long LL;
#define MAXN 30
#define L 100006
#define MOD 1000000007
#define INF 1000000009
const double eps = 1e-;
/*
这个题目跟之前做的有一定区别,之前做的大多是表示一个序列的转移矩阵(用一列 列向量表示一个序列的几项)
而这个题给出了 an 的转移关系 bn的转移关系 要求 an*bn的前n项和
应当扩充列的范围(矩阵表达的含义增加)
【An Bn An*Bn Sum(n)】 转移关系是很好列的,剩下的就是矩阵快速幂
*/
LL n, a0, ax, ay, b0, bx, by;
struct Mat
{
LL a[][];
Mat()
{
memset(a, , sizeof(a));
}
Mat operator*(const Mat& rhs)
{
Mat ret;
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
if(a[i][j])
{
for (int k = ; k < ; k++)
{
ret.a[i][k] = (ret.a[i][k] + a[i][j] * rhs.a[j][k]) % MOD;
}
}
}
}
return ret;
}
};
Mat fpow(Mat m, LL b)
{
Mat ans;
for (int i = ; i < ; i++)
ans.a[i][i] = ;
while (b != )
{
if (b & )
ans = m * ans;
m = m * m;
b = b / ;
}
return ans;
}
int main()
{
while (scanf("%lld", &n) != EOF)
{
scanf("%lld%lld%lld%lld%lld%lld", &a0, &ax, &ay, &b0, &bx, &by);
if (n == )
{
printf("0\n");
continue;
}
Mat M;
M.a[][] = ax%MOD, M.a[][] = ax%MOD*by%MOD, M.a[][] = ax%MOD*by%MOD;
M.a[][] = bx%MOD, M.a[][] = M.a[][] = bx%MOD*ay%MOD;
M.a[][] = M.a[][] = ax%MOD*bx%MOD;
M.a[][] = ;
M.a[][] = ay%MOD, M.a[][] = by%MOD, M.a[][] = M.a[][] = ay%MOD*by%MOD, M.a[][] = ;
if (n == )
printf("%lld\n", a0*b0%MOD);
else
{
M = fpow(M, n - );
LL ans = ;
ans = (ans + a0*M.a[][] % MOD) % MOD;
ans = (ans + b0*M.a[][] % MOD) % MOD;
ans = (ans + +a0%MOD*b0%MOD*M.a[][] % MOD) % MOD;
ans = (ans + a0%MOD*b0%MOD*M.a[][] % MOD) % MOD;
ans = (ans +M.a[][] % MOD) % MOD;
printf("%lld\n", ans);
}
}
}
S - Arc of Dream 矩阵快速幂的更多相关文章
- HDU4686 Arc of Dream 矩阵快速幂
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 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 ...
- 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 ...
- HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...
- hdu----(4686)Arc of Dream(矩阵快速幂)
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU4686 Arc of Dream —— 矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-4686 Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memo ...
- HDOJ 4686 Arc of Dream 矩阵高速幂
矩阵高速幂: 依据关系够建矩阵 , 高速幂解决. Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/ ...
- hdu 4686 Arc of Dream_矩阵快速幂
题意:略 构造出矩阵就行了 | AX 0 AXBY AXBY 0 | ...
- hdu4686 Arc of Dream ——构造矩阵+快速幂
link: http://acm.hdu.edu.cn/showproblem.php?pid=4686 构造出来的矩阵是这样的:根据题目的ai * bi = ……,可以发现 矩阵1 * 矩阵3 = ...
随机推荐
- 洛谷P5055 【模板】可持久化文艺平衡树(FHQ Treap)
题面 传送门 题解 日常敲板子.jpg //minamoto #include<bits/stdc++.h> #define R register #define inline __inl ...
- JQ 获取Table的td 值
<script type="text/javascript"> function SetTable() { $("#myTab table").ea ...
- RabbitMQ~广播消息
定义 广播消息是指生产者产生的消息将分发给所有订阅这个消息的消费者,而普通的模式是:一批消息可以被多个人共同消费,如consumer1可能消费1,3,5记录,而consumer2可能消费的是2,4,6 ...
- 关于sql的case when用法简述
刚入手公司项目,需要添加一个功能,用到了SQL的case when以及concat SELECT eve.cc, eve.sc, case concat(cc,sc) ' THEN '' ' THEN ...
- [ NOI 2001 ] 食物链
\(\\\) Description 有三类动物 \(A,B,C\),满足\(A\) 吃 \(B\),\(B\)吃 \(C\),\(C\) 吃 \(A\). 现有 \(N\) 个动物,以 \(1 - ...
- vs2012 jsoncpp 链接错误
解决: 项目->属性->C/C++->代码生成->运行库->设置与使用的.lib的版本一致.
- Python批量下载电视剧电影--自己动手丰衣足食
前言 为了看美剧<天蝎>,在电影天堂找到了,于是就想下载下来好好欣赏. 废话不说了,直接上代码. 代码 import requests,re,os,time url = "htt ...
- Redis系列(九)--几道面试题
这里只是一点面试题,想了解更多,可以查看本人的Redis系列:https://www.cnblogs.com/huigelaile/category/1461895.html 1.Redis和Memc ...
- Invalid character found in the request target.The valid characters are defined in RFC 7230 and RFC3986
Tomcat在 7.0.73, 8.0.39, 8.5.7 版本后,添加了对于http头的验证. 具体来说,就是添加了些规则去限制HTTP头的规范性 参考这里 具体来说: org.apache.tom ...
- A5. JVM 如何判断GC对象
[概述] 在堆里面存放着 Java 世界中几乎所有的对象实例,垃圾收集器在对堆进行回收前,第一件事情就是要确定这些对象之中哪些还 “存活” 着,哪些已经 “死去”(即不可能再被任何途径使用的对象). ...