矩阵高速幂:

依据关系够建矩阵 , 高速幂解决.

Arc of Dream

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)

Total Submission(s): 2164    Accepted Submission(s): 680

Problem Description
An Arc of Dream is a curve defined by following function:




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?

 
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 1018, and all the other integers are no more than 2×109.
 
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
 
Author
Zejun Wu (watashi)
 
Source
 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; typedef long long int LL; const LL mod=1000000007LL; struct Matrix
{
int x,y;
LL m[6][6];
Matrix() {x=y=5;memset(m,0,sizeof(m));}
void one()
{
for(int i=0;i<5;i++) m[i][i]=1LL;
}
void show()
{
cout<<x<<" * "<<y<<endl;
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
cout<<m[i][j]<<",";
cout<<endl;
}
}
}; Matrix Mul(Matrix& a,Matrix& b)
{
Matrix ret;
ret.x=a.x; ret.y=b.y;
for(int i=0;i<a.x;i++)
{
for(int j=0;j<b.y;j++)
{
LL temp=0;
for(int k=0;k<b.y;k++)
{
temp=(temp+(a.m[i][k]*b.m[k][j])%mod)%mod;
}
ret.m[i][j]=temp%mod;
}
}
return ret;
} Matrix quickPow(Matrix m,LL x)
{
Matrix e;
e.one();
while(x)
{
if(x&1LL) e=Mul(e,m);
m=Mul(m,m);
x/=2LL;
}
return e;
} LL n,A0,B0,AX,AY,BX,BY; Matrix init_matrix()
{
Matrix ret;
ret.m[0][0]=1;
ret.m[1][0]=AY; ret.m[1][1]=AX;
ret.m[2][0]=BY; ret.m[2][2]=BX;
ret.m[3][0]=(BY*AY)%mod; ret.m[3][1]=(AX*BY)%mod;
ret.m[3][2]=(BX*AY)%mod; ret.m[3][3]=(AX*BX)%mod;
ret.m[4][3]=1LL; ret.m[4][4]=1LL;
return ret;
} Matrix Beg()
{
Matrix beg;
beg.m[0][0]=1;
beg.m[1][0]=A0;
beg.m[2][0]=B0;
beg.m[3][0]=A0*B0%mod;
return beg;
} int main()
{
while(cin>>n)
{
cin>>A0>>AX>>AY>>B0>>BX>>BY;
A0=A0%mod; AX=AX%mod; AY=AY%mod;
B0=B0%mod; BX=BX%mod; BY=BY%mod;
Matrix m=init_matrix();
m=quickPow(m,n);
Matrix beg=Beg();
LL ans=0;
for(int i=0;i<5;i++)
ans=(ans+beg.m[i][0]*m.m[4][i]%mod)%mod;
cout<<ans<<endl;
}
return 0;
}

HDOJ 4686 Arc of Dream 矩阵高速幂的更多相关文章

  1. 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 ...

  2. HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...

  3. HDU4686 Arc of Dream 矩阵快速幂

    Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  4. 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  ...

  5. hdu----(4686)Arc of Dream(矩阵快速幂)

    Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  6. 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 ...

  7. HDU 4686 Arc of Dream(矩阵)

    Arc of Dream [题目链接]Arc of Dream [题目类型]矩阵 &题解: 这题你做的复杂与否很大取决于你建的矩阵是什么样的,膜一发kuangbin大神的矩阵: 还有几个坑点: ...

  8. HDU4686 Arc of Dream —— 矩阵快速幂

    题目链接:https://vjudge.net/problem/HDU-4686 Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memo ...

  9. HDOJ 5411 CRB and Puzzle 矩阵高速幂

    直接构造矩阵,最上面一行加一排1.高速幂计算矩阵的m次方,统计第一行的和 CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory ...

随机推荐

  1. 如何使用git工具向github提交代码

    大致分为以下几个步骤 安装git环境,工具使用msysgit github上的账号 首先在github上点击头像旁边的加号 add new ,选择new Repository,自己创建一个名字,假设取 ...

  2. Python3使用setuptools

    旧版的setuptools已经不能用于Python3上了,国外有大神fork出了另一分支distribute,它可以支持Python3:     1 2 3 4 5 6 7 #下载 wget http ...

  3. HDU 3436 Queue-jumpers (splay tree)

    Queue-jumpers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  4. Android App的签名

    Andriod应用程序如果要在手机或模拟器上安装,必须要有签名! 签名的意义 为了保证每个应用程序开发商合法ID,防止部分开放商可能通过使用相同的Package Name来混淆替换已经安装的程序, 我 ...

  5. 【Go入门教程4】变量(var),常量(const),内置基础类型(Boolean、数值 byte,int,rune、字符串、错误类型),分组,iota枚举,array(数值),slice(切片),map(字典),make/new操作,零值

    这小节我们将要介绍如何定义变量.常量.Go 内置类型以及 Go 程序设计中的一些技巧. 定义变量 Go 语言里面定义变量有多种方式. 使用 var 关键字是 Go 最基本的定义变量方式,与 C 语言不 ...

  6. IDC门外汉-单线、双线、智能多线、BGP的区别

    一.单线在此不多说,不是电信,就是网通机房,是,2005年前的机房情况: 二.双线:上般是从2004年到2008年用此方法较多,此今还有不少在用此法如下: 双线主机 有单IP和单网卡双IP地址,双网卡 ...

  7. 在没有界面的类中,实现弹出UIAlertView || 在没有界面的类中,刷新程序界面 思路

    +(DisplayErrorMsg *)sharedDisplayErrorMsg { static DisplayErrorMsg *instance = nil; @synchronized(in ...

  8. linux统计文件夹内文件数

    for dir in `find ./ -type d ` ;do echo -n "$dir "  ;find $dir  -type f | wc -l ;echo " ...

  9. 《软件开发与创新:ThoughtWorks文集:续集》

    <软件开发与创新:ThoughtWorks文集:续集> 基本信息 原书名:The thoughtWorks anthology, volume 2:More essays on softw ...

  10. flume 日志导入elasticsearch

    Flume配置 . flume生成的数据结构 <span style="font-size:18px;">"_index" : "logs ...