hdu----(4686)Arc of Dream(矩阵快速幂)
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

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?
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.
1 2 3
4 5 6
2
1 2 3
4 5 6
3
1 2 3
4 5 6
134
1902
然后我们知道ai=ai-1*AX+AY ; bi=bi-1*BX+BY;#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(矩阵快速幂)的更多相关文章
- 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_矩阵快速幂
题意:略 构造出矩阵就行了 | AX 0 AXBY AXBY 0 | ...
- 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 ...
- 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 ...
- HDOJ 4686 Arc of Dream 矩阵高速幂
矩阵高速幂: 依据关系够建矩阵 , 高速幂解决. Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/ ...
- HDU 4686 Arc of Dream(矩阵)
Arc of Dream [题目链接]Arc of Dream [题目类型]矩阵 &题解: 这题你做的复杂与否很大取决于你建的矩阵是什么样的,膜一发kuangbin大神的矩阵: 还有几个坑点: ...
- HDU4686 Arc of Dream —— 矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-4686 Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memo ...
随机推荐
- c# SendMail
using System; using System.Collections.Generic; using System.Net; using System.Net.Mail; using Syste ...
- Win 64 register usage
http://www.mouseos.com/win64/registers.html Seems UEFI using rcx, rdx, r8, r9, r10, r11, r12 to stor ...
- 服务器端验证--验证框架验证required.
struts2表单验证里field-validator type值一共可以取哪些?都什么含义? int 整数:double 实数:date 日期:expression 两数的关系比较: email E ...
- Servlet&jsp基础:第一部分
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- 使用ansible批量管理远程服务器
使用ansible批量管理远程服务器 背景 本地需要管理远程的一批服务器,主要执行以下任务: 1) 将本地的文件复制到远端所有服务器: 2) 需要在远程服务器中执行一个个命令: 远端服务器路径并非完全 ...
- Quartz.Net 调度框架配置介绍
在平时的工作中,估计大多数都做过轮询调度的任务,比如定时轮询数据库同步,定时邮件通知等等.大家通过windows计划任务,windows服务等都实现过此类任务,甚至实现过自己的配置定制化的框架.那今天 ...
- Spring的DI(Ioc) - 注入集合类型
1: 首先给service添加集合类型的属性,并提供getter, setter package cn.gbx.serviceimpl; import java.util.ArrayList; imp ...
- HDU 1003 Max Sum 解题报告
题目大意:求一串数字中,几个连续数字加起来最大值,并确定起始和最末的位置. 思路:这是一题DP题,但是可以用尺取法来做.我一开始不会,也是看了某大神的代码,然后有人告诉我这是尺取法,现在会了. //尺 ...
- 加载.properties方式
相对路径时注意:是相对项目(即包下)还是相对当前类(一般都是相对当前项目)(对于非class的资源文件eclipse编译时会直接放到bin目录下) 1.一般是从目录中加载:需要指明路径 2.另外就是通 ...
- adb_常用命令
1. adb push 电脑中的文件(包含路径) Android中的绝对路径 2. adb pull Android中的绝对路径文件 电脑中的绝对路径 3. adb install ??.ap ...