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. Codeforces Round #455 (Div. 2)

    Codeforces Round #455 (Div. 2) A. Generate Login 题目描述:给出两个字符串,分别取字符串的某个前缀,使得两个前缀连起来的字符串的字典序在所有方案中最小, ...

  2. AWS 使用总结

    A.升配置的流程: 1.新开一台配置较高的机器; 2.将新机器和老机器的磁盘都取消关联,注意需要记录下老机器的磁盘分区设备名,如:/dev/sda1: 3.将老机器的磁盘挂载到新机器上,磁盘分区设备名 ...

  3. [ python ] 网络编程(1)

    在本地电脑上有两个python文件 regist.py .login.py 一个注册,一个登录.这两个python一个是写用户信息,一个是读用户信息,要怎么做呢? 通过之前的知识,我们可以通过 reg ...

  4. 在 ASP.NET Core 具体使用文档

    https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/hosting?tabs=aspnetcore2x

  5. Linux自身安全SElinux

    查看SELinux状态: 1./usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态 SELinux status:         ...

  6. hbase学习(二)hbase单机和高可用完全分布式安装部署

    hbase版本 2.0.4  与hadoop兼容表http://hbase.apache.org/book.html#hadoop  我的 hadoop版本是3.1   1.单机版hbase 1.1解 ...

  7. Valid Parentheses——栈经典

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  8. electron 使用中的注意事项

    一.ELECTRON引用JQUERY.JS electron不能像正常的html文件引用jq.js那样(为嘛不造),elecron引用jq.js的方式为: <script>window.$ ...

  9. 很好的开源UI框架Chico UI

    介绍一个很好的开源的UI框架,依赖于jquery 官网:http://www.chico-ui.com.ar/ 以下是相关截图: 消息提示 自动完成 分页,列表 Chico UI是什么? Chico ...

  10. explode() 字符串转换数组

    explode() 函数把字符串分割为数组. 语法 explode(separator,string,limit) 例子: $str = "Hello world. It's a beaut ...