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

where
a0 = A0
ai = ai-*AX+AY
b0 = B0
bi = bi-*BX+BY
What is the value of AoD(N) modulo ,,,?
 
Input
There are multiple test cases. Process to the End of File.
Each test case contains nonnegative integers as follows:
N
A0 AX AY
B0 BX BY
N is no more than , and all the other integers are no more than ×.
Output
For each test case, output AoD(N) modulo ,,,.
 
Sample Input

 
Sample Output

 
Author
Zejun Wu (watashi)
 
Source
 

因为:a[i]*b[i]=(a[i-1]*AX+AY)*(b[i-1]*BX+BY)

      =(a[i-1]*b[i-1]*AX*BX+a[i-1]*AX*BY+b[i-1]*BX*AY+AY*BY)

构造矩阵:

                                                          |  1         0    0     0      0   |

                                                          |  AX*BY   AX   0     AX*BY    0   |

           {AoD(n-1),a[i-1],b[i-1],a[i-1]*b[i-1],1}*      |  BX*AY    0   BX    BX*AY    0   |      ={AoD(n),a[i],b[i],a[i]*b[i],1}

                                                          |  AX*BX    0   0      AX*BX   0   |

                                                          |  AY*BY   AY   BY    AY*BY    1   |

 

 

另外注意:

if(n==0){//这个判断条件很重要,没有就会超时
printf("0\n");
continue;
}

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 1000000
#define inf 1e12
ll n;
ll A0,Ax,Ay,B0,Bx,By;
struct Matrix{
ll mp[][];
};
Matrix Mul(Matrix a,Matrix b){
Matrix res;
for(ll i=;i<;i++){
for(ll j=;j<;j++){
res.mp[i][j]=;
for(ll k=;k<;k++){
res.mp[i][j]=(res.mp[i][j]+(a.mp[i][k]*b.mp[k][j])%MOD+MOD)%MOD;
}
}
}
return res;
}
Matrix fastm(Matrix a,ll b){
Matrix res;
memset(res.mp,,sizeof(res.mp));
for(ll i=;i<;i++){
res.mp[i][i]=;
}
while(b){
if(b&){
res=Mul(res,a);
}
a=Mul(a,a);
b>>=;
}
return res;
}
int main()
{
while(scanf("%I64d",&n)==){
scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&A0,&Ax,&Ay,&B0,&Bx,&By); if(n==){//这个判断条件很重要,没有就会超时
printf("0\n");
continue;
} ll a0=A0;
ll b0=B0; Matrix tmp;
memset(tmp.mp,,sizeof(tmp.mp));
tmp.mp[][]=%MOD;
tmp.mp[][]=Ax*By%MOD;
tmp.mp[][]=Ax%MOD;
tmp.mp[][]=Ax*By%MOD;
tmp.mp[][]=Bx*Ay%MOD;
tmp.mp[][]=Bx%MOD;
tmp.mp[][]=Bx*Ay%MOD;
tmp.mp[][]=Ax*Bx%MOD;
tmp.mp[][]=Ax*Bx%MOD;
tmp.mp[][]=Ay*By%MOD;
tmp.mp[][]=Ay%MOD;
tmp.mp[][]=By%MOD;
tmp.mp[][]=Ay*By%MOD;
tmp.mp[][]=%MOD; Matrix cnt=fastm(tmp,n-); Matrix g;
memset(g.mp,,sizeof(g.mp));
g.mp[][]=a0*b0%MOD;
g.mp[][]=a0%MOD;
g.mp[][]=b0%MOD;
g.mp[][]=a0*b0%MOD;
g.mp[][]=%MOD;
Matrix ans=Mul(g,cnt);
printf("%I64d\n",ans.mp[][]);
}
return ;
}

hdu 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. hdu 4686 Arc of Dream_矩阵快速幂

    题意:略 构造出矩阵就行了 |   AX   0    AXBY   AXBY       0  |                                                   ...

  4. HDU4686 Arc of Dream 矩阵快速幂

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

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

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

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

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

  8. HDOJ 4686 Arc of Dream 矩阵高速幂

    矩阵高速幂: 依据关系够建矩阵 , 高速幂解决. Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/ ...

  9. HDU 4686 Arc of Dream(矩阵)

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

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

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

随机推荐

  1. C# Switch is Type

    常规用法: Type t = sender.GetType(); if (t == typeof(Button)) { var realObj = (Button)sender; // Do Some ...

  2. Container With Most Water 解答

    Question Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate ...

  3. vector迭代器失效的一种情形

    使用过STL的人都应该知道关于迭代器失效的原理,这里以后vector迭代器失效为例: 第一种:当插入一个元素到vector中,如果插入后容器已满,那么容器将新开辟一块内存区域,然后 将原内存中的数据拷 ...

  4. ZOJ3477&JAVA大数类

    转:http://blog.csdn.net/sunkun2013/article/details/11822927 import java.util.*; import java.math.BigI ...

  5. jquery实现仿商品星级评价

    一,HTML部分 <div id="rating-star">     <a href="#">0</a>     < ...

  6. 在EasyUI中统一判断是否有选中行,如果有则将选中行数据传入回调函数

    function procossWithSeletedData(func) { var rowData = $("#tbGrid").datagrid("getSelec ...

  7. C# 静态类与非静态类、静态成员的区别分析

    静态类静态类与非静态类的重要区别在于静态类不能实例化,也就是说,不能使用 new 关键字创建静态类类型的变量.在声明一个类时使用static关键字,具有两个方面的意义:首先,它防止程序员写代码来实例化 ...

  8. hdu2304Electrical Outlets

    Problem Description Roy has just moved into a new apartment. Well, actually the apartment itself is ...

  9. [Linked List]Insertion Sort List

    Total Accepted: 59422 Total Submissions: 213019 Difficulty: Medium Sort a linked list using insertio ...

  10. ubuntu安装体验

    本文记录一下昨晚及今天安装ubuntu系统的过程及体验 2016年6月13日09:36:11 更新 今天才有发现原来自己有个没填的坑 = = 那次安乌班图后第一感觉是很好用,新鲜了好几天,但是很快,新 ...