Arc of Dream

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

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)

很明显是要构造矩阵,然后用矩阵快速幂求解。

|   AX   0   AXBY   AXBY  0  |

|   0   BX  AYBX    AYBX  0  |

{a[i-1]   b[i-1]   a[i-1]*b[i-1]  AoD[i-1]  1}* |   0   0   AXBX    AXBX   0  |  = {a[i]   b[i]   a[i]*b[i]  AoD[i]  1}

|    0   0     0          1     0    |

|  AY  BY   AYBY   AYBY   1   |

然后就可以搞了

注意n==0的时候,输出0

 /* ***********************************************
Author :kuangbin
Created Time :2013/8/20 12:21:51
File Name :F:\2013ACM练习\2013多校9\1001.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int MOD = 1e9+;
struct Matrix
{
int mat[][];
void clear()
{
memset(mat,,sizeof(mat));
}
void output()
{
for(int i = ;i < ;i++)
{
for(int j = ;j < ;j++)
printf("%d ",mat[i][j]);
printf("\n");
}
}
Matrix operator *(const Matrix &b)const
{
Matrix ret;
for(int i = ;i < ;i++)
for(int j = ;j < ;j++)
{
ret.mat[i][j] = ;
for(int k = ;k < ;k++)
{
long long tmp = (long long)mat[i][k]*b.mat[k][j]%MOD;
ret.mat[i][j] = (ret.mat[i][j]+tmp);
if(ret.mat[i][j]>MOD)
ret.mat[i][j] -= MOD;
}
}
return ret;
}
};
Matrix pow_M(Matrix a,long long n)
{
Matrix ret;
ret.clear();
for(int i = ;i < ;i++)
ret.mat[i][i] = ;
Matrix tmp = a;
while(n)
{
if(n&)ret = ret*tmp;
tmp = tmp*tmp;
n>>=;
}
return ret;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
long long n;
int A0,AX,AY;
int B0,BX,BY;
while(scanf("%I64d",&n) == )
{
scanf("%d%d%d",&A0,&AX,&AY);
scanf("%d%d%d",&B0,&BX,&BY);
if(n == )
{
printf("0\n");
continue;
}
Matrix a;
a.clear();
a.mat[][] = AX%MOD;
a.mat[][] = (long long)AX*BY%MOD;
a.mat[][] = BX%MOD;
a.mat[][] = (long long)AY*BX%MOD;
a.mat[][] = (long long)AX*BX%MOD;
a.mat[][] = ;
a.mat[][] = AY%MOD;
a.mat[][] = BY%MOD;
a.mat[][] = (long long)AY*BY%MOD;
a.mat[][] = ;
a.mat[][] = a.mat[][];
a.mat[][] = a.mat[][];
a.mat[][] = a.mat[][];
a.mat[][] = a.mat[][];
//a.output();
a = pow_M(a,n-);
//a.output();
long long t1 = (long long)A0*B0%MOD;
long long ans = t1*a.mat[][]%MOD + t1*a.mat[][]%MOD;
if(ans > MOD)ans -= MOD;
ans += (long long)A0*a.mat[][];
ans %= MOD;
ans += (long long)B0*a.mat[][];
ans %= MOD;
ans += (long long)a.mat[][];
ans %= MOD;
printf("%d\n",(int)ans);
}
return ;
}

HDU 4686 Arc of Dream (2013多校9 1001 题,矩阵)的更多相关文章

  1. HDU 4611 Balls Rearrangement(2013多校2 1001题)

    Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  2. HDU 4655 Cut Pieces(2013多校6 1001题 简单数学题)

    Cut Pieces Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total ...

  3. HDU 4696 Answers (2013多校10,1001题 )

    Answers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total S ...

  4. HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  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. hdu 4686 Arc of Dream(矩阵快速幂乘法)

    Problem Description An Arc of Dream is a curve defined by following function: where a0 = A0 ai = ai- ...

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

    标题效果:你就是给你一程了两个递推公式公式,第一个让你找到n结果项目. 注意需要占用该公式的复发和再构造矩阵. Arc of Dream Time Limit: 2000/2000 MS (Java/ ...

  8. HDU 4686 Arc of Dream(矩阵)

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

  9. HDU 4691 Front compression (2013多校9 1006题 后缀数组)

    Front compression Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Othe ...

随机推荐

  1. php琐碎

    1.类中的常量,可以用类来引用: class MyClass() { const SUCCESS ="success"; const FAIL ="fail"; ...

  2. Cookie对象与Session对象-java

    1.Cookie对象 1.1常见的方法 (1)创建Cookie对象,绑定数据 new Cookie(String name, String value) (2)发送Cookie对象 response. ...

  3. SGU 209. Areas

    209. Areas time limit per test: 0.25 sec.memory limit per test: 65536 KB input: standardoutput: stan ...

  4. open()函数文件操作

    open函数,该函数用于文件处理 操作文件时,一般需要经历如下步骤: (1)打开文件 (2)操作文件 一.打开文件     文件句柄 = open("文件路径","模式& ...

  5. mongodb卸载再重装

    标题就凸显了尴尬,是的,本地(ubuntu16.04)自带的mongodb太老了,想要装最新版的 卸载: sudo dpkg -P mongodb 然后下载新版的mongodb:  https://m ...

  6. mybatis基础之一

    SqlMapConfig.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE conf ...

  7. [Codeforces50C]Happy Farm 5 凸包

    大致题意: 平面上有n个整数点,问你最少经过多少步能够将所有点严格包围. 将点严格包围要求你走的路径完全包围给出的点且不能有点在路径上 你只能走整数点,且方向只有上下左右左上右下等8个方向,每次移动一 ...

  8. iOS 9音频应用播放音频之ios9音频基本功能

    iOS 9音频应用播放音频之ios9音频基本功能 在iOS 9音频应用开发中最为简单和常用的就是AVFoundation框架中的AVAudioPlayer类.虽然AVAudioPlayer类不能播放网 ...

  9. Lisp em SCU - 4490 (强大的map用法)

    Time Limit: 1000 MS Memory Limit: 131072 K Description There are two lists and they may be intersect ...

  10. VS2015快捷键及常用功能

    写下这些快捷键的操作,并不是全部记住,记住常用的,然后其他的来查询就好了. 1.回到上一个光标位置/前进到下一个光标位置 1)回到上一个光标位置:使用组合键“Ctrl + -”; 2)前进到下一个光标 ...