HDU 4686 Arc of Dream(递归矩阵加速)

简介:

标题效果:你就是给你一程了两个递推公式公式,第一个让你找到n结果项目。

注意需要占用该公式的复发和再构造矩阵。

Arc of Dream

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 2092    Accepted Submission(s): 664


Problem Description
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
b i = b i-1*BX+BY
What is the value of AoD(N) modulo 1,000,000,007?
 

Input
There 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.
 

Output
For 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
 

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
///#define M 1000100
#define LL __int64
///#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?

0:x) #define mod 1000000007 const int maxn = 210; using namespace std; struct matrix { LL f[10][10]; }; matrix mul(matrix a, matrix b, int n) { matrix c; memset(c.f, 0, sizeof(c.f)); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { for(int k = 0; k < n; k++) c.f[i][j] += a.f[i][k]*b.f[k][j]; c.f[i][j] %= mod; } } return c; } matrix pow_mod(matrix a, LL b, int n) { matrix s; memset(s.f, 0 , sizeof(s.f)); for(int i = 0; i < n; i++) s.f[i][i] = 1LL; while(b) { if(b&1) s = mul(s, a, n); a = mul(a, a, n); b >>= 1; } return s; } matrix Add(matrix a,matrix b, int n) { matrix c; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { c.f[i][j] = a.f[i][j]+b.f[i][j]; c.f[i][j] %= mod; } } return c; } int main() { LL n; LL a, ax, ay; LL b, bx, by; while(~scanf("%I64d",&n)) { scanf("%I64d %I64d %I64d",&a, &ax, &ay); scanf("%I64d %I64d %I64d",&b, &bx, &by); a %= mod; ax %= mod; ay %= mod; b %= mod; bx %= mod; by %= mod; LL ff = a*b%mod; LL x = (a*ax+ay)%mod; LL y = (b*bx+by)%mod; LL pp = (x*y)%mod; if(n == 0) { puts("0"); continue; } matrix c; memset(c.f, 0 ,sizeof(c.f)); c.f[0][0] = ax*bx%mod; c.f[0][1] = ax*by%mod; c.f[0][2] = ay*bx%mod; c.f[0][3] = ay*by%mod; ///c.f[0][4] = 1LL; c.f[1][1] = ax; c.f[1][3] = ay; c.f[2][2] = bx; c.f[2][3] = by; c.f[3][3] = 1LL; c.f[4][0] = 1LL; c.f[4][4] = 1LL; matrix d = pow_mod(c, n-1LL, 5); LL sum = 0LL; sum += ((d.f[4][0]*pp%mod)+(d.f[4][4]*ff%mod))%mod; sum += ((d.f[4][1]*x%mod) + (d.f[4][2]*y%mod) + d.f[4][3]%mod)%mod; printf("%I64d\n",(sum+mod)%mod); } return 0; }



版权声明:本文博客原创文章,博客,未经同意,不得转载。






本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4751937.html,如需转载请自行联系原作者


相关文章
|
8月前
|
Shell 网络安全 虚拟化
XPipe:一款新型开源终端管理神器
XPipe 是一款创新的 Shell 连接中心和远程文件管理器,它能够让你从本地机器轻松访问整个服务器基础设施。这款工具运行在你已安装的命令行程序之上,无需在远程系统上进行任何额外配置。因此,如果你通常使用 CLI 工具(如 ssh、docker、kubectl 等)来连接服务器,你可以直接在 XPipe 上使用这些工具,极大地简化了操作流程。
371 15
XPipe:一款新型开源终端管理神器
|
存储 传感器 监控
未来城市的智慧交通系统
智慧交通系统是未来城市发展的重要组成部分,通过整合物联网、大数据和人工智能技术,实现交通的智能化管理。本文探讨了智慧交通系统的关键技术、架构及其在实际应用中的案例,并展望了未来的发展趋势。
|
Ubuntu 编译器 计算机视觉
Ubuntu系统编译OpenCV4.8源码
【10月更文挑战第17天】只要三步即可搞定,第一步是下载指定版本的源码包;第二步是安装OpenCV4.8编译需要的编译器与第三方库支持;第三步就是编译OpenCV源码包生成安装文件并安装。
191 4
|
Python
Python 中的 spell checker 库
Python 中的 spell checker 库
410 1
|
数据采集 机器学习/深度学习 存储
使用 Python 清洗日志数据
使用 Python 清洗日志数据
236 2
|
数据库 索引
DROP INDEX 语句
【7月更文挑战第20天】DROP INDEX 语句。
440 2
|
安全 测试技术 数据库连接
什么是防御式编程?
防御式编程是一种编程策略,主要目的是提高代码的健壮性和可靠性。它假设任何错误都可能发生,并且在设计和编写代码时采取预防措施以防止这些错误导致程序崩溃或产生错误结果。
224 4
|
数据可视化 网络协议 Linux
Linux 怎样通过win 远程桌面连接链接Linux后台服务器的可视化图形界面
Linux 怎样通过win 远程桌面连接链接Linux后台服务器的可视化图形界面
290 0
|
开发者
同济大学系统结构 实验一:MIPS指令系统和MIPS体系结构-4
同济大学系统结构 实验一:MIPS指令系统和MIPS体系结构-4
711 0
同济大学系统结构 实验一:MIPS指令系统和MIPS体系结构-4
|
Shell Linux 网络安全
Termux安装Linux
Termux安装Linux
1032 2