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): 419 Accepted Submission(s): 148

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
http://www.cnblogs.com/liuxueyang/archive/2013/08/20/3270893.html
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int mod=; struct Matrix{
long long arr[][];
}; Matrix init,unit;
long long n,a0,ax,ay,b0,bx,by; //注意用long long,否则会溢出 Matrix Mul(Matrix a,Matrix b){
Matrix c;
for(int i=;i<;i++)
for(int j=;j<;j++){
c.arr[i][j]=;
for(int k=;k<;k++)
c.arr[i][j]=(c.arr[i][j]+a.arr[i][k]*b.arr[k][j]%mod)%mod;
c.arr[i][j]%=mod;
}
return c;
} Matrix Pow(Matrix a,Matrix b,long long k){
while(k){
if(k&){
b=Mul(b,a);
}
a=Mul(a,a);
k>>=;
}
return b;
} void Init(){
for(int i=;i<;i++)
for(int j=;j<;j++){
init.arr[i][j]=;
unit.arr[i][j]=;
}
unit.arr[][]=, unit.arr[][]=a0%mod, unit.arr[][]=b0%mod, unit.arr[][]=a0*b0%mod,
unit.arr[][]=a0*b0%mod; init.arr[][]=, init.arr[][]=ay%mod, init.arr[][]=by%mod, init.arr[][]=ay*by%mod,
init.arr[][]=ay*by%mod, init.arr[][]=ax%mod, init.arr[][]=ax*by%mod, init.arr[][]=ax*by%mod,
init.arr[][]=bx%mod, init.arr[][]=ay*bx%mod, init.arr[][]=ay*bx%mod, init.arr[][]=ax*bx%mod,
init.arr[][]=ax*bx%mod, init.arr[][]=;
} int main(){ //freopen("input.txt","r",stdin); while(cin>>n){
//scanf("%d%d%d%d%d%d",&a0,&ax,&ay,&b0,&bx,&by);
cin>>a0>>ax>>ay>>b0>>bx>>by;
if(n==){
puts("");
continue;
}
Init();
Matrix ans=Pow(init,unit,n-);
cout<<ans.arr[][]<<endl;
}
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 ...
- hdu----(4686)Arc of Dream(矩阵快速幂)
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 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 ...
随机推荐
- com.alibaba.fastjson.JSONObject学习
JSONObject json = new JSONObject(); //设置json属性,可以是对象,数值 json.put("key",value); //获取json的普通 ...
- 今天开始着手原来Office系统的重构
原来系统架构Spring+Hibernate+Struts+springsecurity 拟改成 Spring+SpringMVC+MyBatis/JDBC+Shiro 同时优化前端的CSS和JQue ...
- [转]Python程序员必须知道的30条编程技巧
30 tips & tricks for Python Programming 1 直接交换两个数字位置 x, y = 10, 20 print(x, y) x, y = y, x prin ...
- 【原创】TP-LINK +ASUS(Tomato) 双无线路由设置WDS
主路由: TP-LINK TL-WR2041N 连接Internet,LAN IP地址:192.168.1.1,启用DHCP, 无线配置如下: 开启WDS功能,wireless为副路由的SSID,BS ...
- C#设计模式(23)——备忘录模式(Memento Pattern)
一.引言 在上一篇博文分享了访问者模式,访问者模式的实现是把作用于某种数据结构上的操作封装到访问者中,使得操作和数据结构隔离.而今天要介绍的备忘者模式与命令模式有点相似,不同的是,命令模式保存的是发起 ...
- TPL实现Task.WhileAll扩展方法
文章翻译整理自 Nikola Malovic 两篇博文: Task.WhileAll Awaitable task progress reporting 当 Task.WhenAll 遇见 Task. ...
- [汇编] 从键盘输入一个一位数字,然后响铃n声
; multi-segment executable file template. data segment ends stack segment dw dup() ends code segment ...
- 2014-3-5 星期三 [New Change && New Start]
昨日进度: [计算方法]:起晚啦,迟到一点,有点困,可能因为睡得太晚吧! [无课]:制作IEEE标准在JAVA中的应用. [组成]:-- [多媒体]:-- [人工智能]:-- [寝室]:学习API. ...
- [stm32] 利用uc-gui封装画图和画线函数移植51上的模拟动画
>_<:这里的动画是黄色矩形区域中一个模仿俯视图的起重机运作动画,一个是模仿主视图的吊钩的运动.通过改变初始Init函数中的数据b_x,b_y实现矩形区域的移动.当实时采集时要首先根据起重 ...
- jQuery的XX如何实现?——1.框架
源码链接:内附实例代码 jQuery使用许久了,但是有一些API的实现实在想不通.于是抽空看了jQuery源码,现在把学习过程中发现的一些彩蛋介绍给大家(⊙0⊙). 下面将使用简化的代码来介绍,主要关 ...