HDU4686 Arc of Dream —— 矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-4686
Arc of Dream
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 5506 Accepted Submission(s): 1713

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
题解:
学习之处:
矩阵所要维护的,要么为变量,要么为常数1,而不是变量再乘上一个系数,或者是一个非1的常数。因为:假如变量需要乘上一个系数,那么可以在n*n矩阵中乘上。同样,如果变量需要加上一个常数,那么在对应1的位置,填上这个常数即可。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e6+; const int Size = ;
struct MA
{
LL mat[Size][Size];
void init()
{
for(int i = ; i<Size; i++)
for(int j = ; j<Size; j++)
mat[i][j] = (i==j);
}
}; MA mul(MA x, MA y)
{
MA ret;
memset(ret.mat, , sizeof(ret.mat));
for(int i = ; i<Size; i++)
for(int j = ; j<Size; j++)
for(int k = ; k<Size; k++)
ret.mat[i][j] += 1LL*x.mat[i][k]*y.mat[k][j]%MOD, ret.mat[i][j] %= MOD;
return ret;
} MA qpow(MA x, LL y)
{
MA s;
s.init();
while(y)
{
if(y&) s = mul(s, x);
x = mul(x, x);
y >>= ;
}
return s;
} int main()
{
LL n, a0, ax, ay, b0, bx, by;
while(scanf("%lld",&n)!=EOF)
{
scanf("%lld%lld%lld", &a0,&ax,&ay);
scanf("%lld%lld%lld", &b0,&bx,&by);
a0 %= MOD; ax %= MOD; ay %= MOD;
b0 %= MOD; bx %= MOD; by %= MOD; if(n==)
{
printf("%lld\n", 0LL);
continue;
} MA s;
memset(s.mat, , sizeof(s.mat));
s.mat[][] = ;
s.mat[][] = s.mat[][] = 1LL*ax*bx%MOD;
s.mat[][] = s.mat[][] = 1LL*ax*by%MOD;
s.mat[][] = s.mat[][] = 1LL*ay*bx%MOD;
s.mat[][] = s.mat[][] = 1LL*ay*by%MOD;
s.mat[][] = ax; s.mat[][] = ay;
s.mat[][] = bx; s.mat[][] = by;
s.mat[][] = ; LL f0, s0;
s0 = f0 = 1LL*a0*b0%MOD;
s = qpow(s, n-);
LL ans = ;
ans += (1LL*s0*s.mat[][]%MOD+1LL*f0*s.mat[][]%MOD)%MOD, ans %= MOD;
ans += (1LL*a0*s.mat[][]%MOD+1LL*b0*s.mat[][]%MOD)%MOD, ans %= MOD;
ans += 1LL*s.mat[][]%MOD, ans %= MOD;
printf("%lld\n", ans);
}
}
HDU4686 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(矩阵快速幂)
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 | ...
随机推荐
- 搭建服务与负载均衡的客户端-Spring Cloud学习第二天(非原创)
文章大纲 一.Eureka中的核心概念二.Spring RestTemplate详解三.代码实战服务与负载均衡的客户端四.项目源码与参考资料下载五.参考文章 一.Eureka中的核心概念 1. 服务提 ...
- 用AntRun插件测试Maven的生命周期
在用AntRun插件之前,需要了解以下几个知识点: 1.Maven的生命周期,参考:http://www.cnblogs.com/EasonJim/p/6816340.html,主要是要知道生命周期里 ...
- fastdfs-zyc监控系统的使用
原文:http://blog.csdn.net/foreversunshine/article/details/51907659 写在前面 前面有介绍过怎么安装与使用FastDFS来进行分布式的文件存 ...
- Weblogic内存溢出及常用参数配置
http://www.360doc.com/content/14/0306/14/16134804_358216319.shtml 一.WebLogic内存溢出 最近访问量门户访问量突然增大, ...
- 微服务指南走北(三):Restful API 设计简述
API的定义取决于选择的IPC通信方式,假设是消息机制(如 AMQP 或者 STOMP).API则由消息频道(channel)和消息类型.假设是使用HTTP机制,则是基于请求/响应(调用http的ur ...
- 并行程序设计---cuda memory
CUDA存储器模型: GPU片内:register,shared memory: host 内存: host memory, pinned memory. 板载显存:local memory,cons ...
- js 数组的迭代
es5新增加的迭代方法(every,filter,forEach,map,some) arr1 = [1,2,3,4,5,6]; 1,every(); every() 方法使用指定函数检测数组中的所有 ...
- java开始到熟悉105-107
1,HashMap基本用法 package list; import java.util.HashMap; import java.util.Map; /** * 测试map的基本用法 * @auth ...
- 我的跟我学Ffmpeg 视频受众有哪些人
经常有人问我如何学习音视频以及如何学习Ffmpeg,问我有没有比较好的书的书推荐.比较好的音视频以及FFmpeg方面的 书,我了解到的比较全面又能深入浅出的还真没有.很多朋友都推荐雷神的博客,雷神的博 ...
- web前端面试系列 - 算法( 数组去重 )
1. 思路:设置一个临时数组temp,然后遍历要去重的数组arr,如果arr中的元素能够在temp中找到,则跳过此元素,否则将此元素存入temp,最后返回temp. 实现一 function uniq ...