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 | ...
随机推荐
- ionic build Android错误记录 error in opening zip file
0.写在前头 运行 :cordova requirements Requirements check results for android: Java JDK: installed 1.8.0 An ...
- 转:PHP 生成复杂JSON格式 简单快速方法
PHP 生成JSON 格式主要使用json_encode()函数.这个函数的输入参数支持PHP数组和对象类型. 查阅网上的例子通常都是使用数组的,也有个别使用对象生成.但实际项目中,我们要生成的JSO ...
- DNS 域名解析过程
当用户在浏览器中输入域名并按下回车键后,DNS解析会有如下7个步骤 浏览器缓存 浏览器会检查缓存中有没有这个域名对应的解析过的IP地址,如果缓存中有,这个解析过程就将结束.浏览器缓存域名也是有限制的, ...
- 转:Json 语法 格式
转自: http://www.cnblogs.com/chencidi/archive/2011/03/24/1993450.html 评注: json 官网如下: http://json.org/j ...
- php-fpm.conf配置说明(重点要改动和优化的地方)
<?xml version="1.0" ?> <configuration> All relative paths in this config are r ...
- Linux命令行编辑常见的快捷键(有用, 通用)
本文讲述了Linux命令行编辑常见的快捷键,希望对您有所帮助. Linux命令行编辑快捷键: history 显示命令历史列表 ↑(Ctrl+p) 显示上一条命令 ↓(Ctrl+n) 显示下一条命令 ...
- Linux退出时出现there are stopped jobs如何解决?
Linux 使用exit时出现there are stopped jobs如何解决? 这是因为一些命令被挂起了, 在后台驻留,需要关闭. 解决问题: 输入命令jobs -l显示停止进程的详细列表 可以 ...
- C# Main(string[] args)方法参数
Main 方法是 C# 控制台应用程序或窗口应用程序的入口点,以下是各种情况下方法参数的输入方式: 1.通过vs启动,需要在“项目属性-调试-启动选项-命令行参数”中配置参数,格式为:参数一 参数二 ...
- ZYThumbnailTableView---堪比一个小型阅读App
Demo github地址: https://github.com/liuzhiyi1992/ZYThumbnailTableView 原文地址:http://zyden.vicp.cc/zythum ...
- codeforces 557 C
由于期末.非常久没刷题了,CF一直掉-- 这个题事实上非常简单. .由于做法非常easy想到嘛.. 就是枚举max=x时,最大能保留多少价值.不断更新ans, 结果就是全部价值和减去ans就好 因为最 ...