HDU4686 Arc of Dream 矩阵快速幂
Arc of Dream
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 4246 Accepted Submission(s): 1332
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.
bi = bi-1*BX+BY
a[i]*b[i] = (a[i-1]*Ax+Ay)(b[i-1]*Bx+By)
= Ax*Bx*a[i-1]*b[i-1]+Ay*Bx*b[i-1]+Ax*By*a[i-1]+Ay*By
s
[s[n-1],a[n-2]*b[n-2], b[n-2], a[n-2], 1]
A
[1 ,0 ,0 ,0 ,0]
[Ax*Bx ,Ax*Bx ,0 ,0 ,0]
[Ay*Bx ,Ay*Bx ,Bx ,0 ,0]
[Ax*By ,Ax*By ,0 ,Ax ,0]
[Ay*By ,Ay*By ,By ,Ay ,1]//n-1
s
[s[n], a[n-1]*b[n-1], b[n-1], a[n-1], 1]
#include<bits/stdc++.h>
#define N 5
#define mes(x) memset(x, 0, sizeof(x));
#define ll long long
const ll mod = 1e9+;
const int MAX = 0x7ffffff;
using namespace std;
struct mat {
ll a[N][N];
mat() {
memset(a, , sizeof(a));
}
mat operator * (mat b) {
mat c;
for (int i = ; i < N; i++)
for (int j = ; j < N; j++)
for (int k = ; k < N; k++)
c.a[i][j] = (c.a[i][j] + a[i][k] * b.a[k][j]) % mod;
return c;
}
};
mat f(mat b, ll m) {
mat c;
for (int i = ; i < N; i++)
c.a[i][i] = ;
while (m) {
if (m & )
c = c * b;
b = b * b;
m >>= ;
}
return c;
}
int main()
{
ll n, A0,Ax, Ay, Bx,By,B0;
mat A, s;
while(~scanf("%lld", &n)){
scanf("%lld%lld%lld%lld%lld%lld", &A0, &Ax, &Ay, &B0, &Bx, &By);
if(n == ){
printf("0\n");
continue;
}
mes(A.a);
mes(s.a);
s.a[][] = s.a[][] = (A0%mod*B0%mod)%mod;
s.a[][] = B0%mod;
s.a[][] = A0%mod;
s.a[][] = ;
A.a[][] = ;
A.a[][] = A.a[][] = (Ax%mod*Bx%mod)%mod;A.a[][] = Bx%mod;
A.a[][] = A.a[][] = (Ay%mod*Bx%mod)%mod;A.a[][] = Ax%mod;
A.a[][] = A.a[][] = (Ax%mod*By%mod)%mod;
A.a[][] = A.a[][] = (Ay%mod*By%mod)%mod;
A.a[][] = By;
A.a[][] = Ay;
A.a[][] = ;
A = f(A,n-);
s = s*A;
printf("%lld\n", (mod+s.a[][])%mod);
}
}
HDU4686 Arc of Dream 矩阵快速幂的更多相关文章
- 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 ...
- HDU4686 Arc of Dream —— 矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-4686 Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memo ...
- hdu----(4686)Arc of Dream(矩阵快速幂)
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 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(矩阵快速幂)
链接: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的递推式题目 ...
- HDOJ 4686 Arc of Dream 矩阵高速幂
矩阵高速幂: 依据关系够建矩阵 , 高速幂解决. Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/ ...
- HDU4686 Arc of Dream 矩阵
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - HDU4686 题意概括 a0 = A0 ai = ai-1*AX+AY b0 = B0 bi = bi-1* ...
- hdu 4686 Arc of Dream_矩阵快速幂
题意:略 构造出矩阵就行了 | AX 0 AXBY AXBY 0 | ...
随机推荐
- Centos配置Caffe详解
http://www.tuicool.com/articles/uiuA3e
- 12---Net基础加强
使用ShowDialog窗体之间的回传值: using System; using System.Collections.Generic; using System.ComponentModel; u ...
- String,StringBuffer,StringBuilder三者区别
String:每次改变,String都会重新构造,内存指针都会改变 StringBuffer:主要用在全局变量中 StringBuilder:在线程内完成字符拼接,因为线程是不安全的,所以完成后可以丢 ...
- Java魔法堂:注释和注释模板 (转)
http://www.cnblogs.com/fsjohnhuang/p/3988883.html 一.注释 1. 注释类型 [a]. 单行注释 // 单行注释 String type = &qu ...
- ThinkPHP讲解(一)框架基础
ThinkPHP框架知识点过于杂乱,接下来将以问题的形势讲解tp(ThinkPHP的简写) 1.tp框架是什么,为什么使用是它? 一堆代码的集合,里边有变量.函数.类.常量,里边也有许多设计模式MVC ...
- POJ - 2041Unreliable Message
这里的算法非常简单,就是“模拟”,注意编写每个传令官的算法时先分开测试,放在一起就会混淆. POJ - 2041Unreliable Message Time Limit: 1000MS Memory ...
- Entity Framework 无法对没有主键的视图映射实体的解决办法
我们在使用Entity Framework的时候经常会把数据库中的某一个视图映射为EF的实体,但是如果数据库视图中的列没有包含表的主键列,EF会报出警告说视图没有主键,导致视图映射为实体失败,错误如下 ...
- Openstack的error僵尸实例的解决办法
在我们对集群环境进行各种调整的情况下,很容易产生一些僵尸实例. 僵尸实例主要是没有该主机,但是在dashboard上,数据库中存在,解决办法网络上有的人给出了繁杂的修改数据库的方法,其实按照下面的命令 ...
- OpenStack 的防火墙规则流程
Contents [hide] 1 发现的问题 2 解决过程 3 删除临时错误数据 4 其实前面的解决办法是错的 发现的问题 3台虚拟机在同一宿主机,防火墙配置都一样,但是他们的网络表现不一致,有的能 ...
- ==,equal,hasCode(),identifyHasCode()浅析
在java中如果我们要比较两个对象之间的关系的话有可能会用到下面的几种方法:==,equal,hasCode(),identifyHasCode(). ==用来比较对象本身是不是相同的. public ...