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

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
1 2 3
4 5 6
2
1 2 3
4 5 6
3
1 2 3
4 5 6
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;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
HDU 4686 Arc of Dream(递归矩阵加速)的更多相关文章
- hdu 4686 Arc of Dream(矩阵快速幂乘法)
Problem Description An Arc of Dream is a curve defined by following function: where a0 = A0 ai = ai- ...
- HDU 4686 Arc of Dream (矩阵快速幂)
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4686 Arc of Dream(矩阵)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 思路: #include <iostream>#include <cs ...
- HDU 4686 Arc of Dream(矩阵)
Arc of Dream [题目链接]Arc of Dream [题目类型]矩阵 &题解: 这题你做的复杂与否很大取决于你建的矩阵是什么样的,膜一发kuangbin大神的矩阵: 还有几个坑点: ...
- HDU 4686 Arc of Dream (2013多校9 1001 题,矩阵)
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 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(快速幂矩阵)
题目链接 再水一发,构造啊,初始化啊...wa很多次啊.. #include <cstring> #include <cstdio> #include <string&g ...
- hdu 4686 Arc of Dream 自己推 矩阵快速幂
A.mat[0][0] = 1, A.mat[0][1] = 1, A.mat[0][2] = 0, A.mat[0][3] = 0, A.mat[0][4] = 0; A.mat[1][0] = 0 ...
随机推荐
- WPF-19:分享一个样式(左右滑动选中的checbox)
首先看下效果. 选中: 不选中 样式: <Style x:Key="CheckStyle" TargetType="{x:Type CheckBox}"& ...
- File already exists: filesystem '/path/file', transaction svn常见错误解决方法
前言 多人任务基本都会用到SVN,于是提交的时候如果不先更新在提交或者操作顺序不对,会经常出现错误,其中File already exists: filesystem这个就是个常见问题,上网找了半天没 ...
- svn简介与使用
本文简单介绍windows下svn服务器与客户端软件的简单应用. 其中,svn服务器用于储存和管理代码,相当与文本服务器的作用(多版本控制等功能),同时分配用户代码的访问与使用权限. 客户端软件 用于 ...
- SSDTHook实例--编写稳定的Hook过滤函数
解说怎样写Hook过滤函数,比方NewZwOpenProcess.打开进程. 非常多游戏保护都会对这个函数进行Hook. 因为我们没有游戏保护的代码,无法得知游戏公司是怎样编写这个过滤函数. 我看到非 ...
- Wix学习整理(6)——安装快捷方式
原文:Wix学习整理(6)--安装快捷方式 一 为HelloWorld案例添加安装快捷方式 通常我们安装一个应用软件的时候,都喜欢在桌面或开始菜单中添加快捷方式以便我们快速访问.现在我们就在上篇添加注 ...
- SE 2014年4月12日
BGP基础实验 拓扑 步骤: 1. 完成基本的配置 2. 按照需求自治系统AS 100 全网运行OSPF 单区域 3. 完成BGP基本配置 [RT2]bgp 100 [RT2-bgp]peer 67. ...
- ubuntu 搭建svn服务器
1.安装Subversion sudo apt-get install subversion 2.创建资源库 cd /home/username/ svnserve -d -r /home/usern ...
- java 调用mysql的存储过程(简单示例)
首先我在mysql的test数据库里定义了一个student表: create table student4( id int primary key, sanme char(5) ); 插入几 ...
- 《Nginx文件类型错误解析漏洞--攻击演练》 (转)
今天看书看到其中提到的一个漏洞,那就是Nginx+PHP的服务器中,如果PHP的配置里 cgi.fix_pathinfo=1 那么就会产生一个漏洞.这个配置默认是1的,设为0会导致很多MVC框架(如T ...
- Java虚拟机几个命令行参数说明
一.运行class文件 执行带main方法的class文件,Java虚拟机命令参数行为: java <CLASS文件名> 注意:CLASS文件名不要带文件后缀.class 例如: java ...