标题效果:你就是给你一程了两个递推公式公式,第一个让你找到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

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
 

#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(递归矩阵加速)的更多相关文章

  1. hdu 4686 Arc of Dream(矩阵快速幂乘法)

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

  2. HDU 4686 Arc of Dream (矩阵快速幂)

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

  3. HDU 4686 Arc of Dream(矩阵)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 思路: #include <iostream>#include <cs ...

  4. HDU 4686 Arc of Dream(矩阵)

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

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

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

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

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

  8. HDU 4686 Arc of Dream(快速幂矩阵)

    题目链接 再水一发,构造啊,初始化啊...wa很多次啊.. #include <cstring> #include <cstdio> #include <string&g ...

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

随机推荐

  1. DecimalFormat

    public class TestDemo { public static void main(String[] args) { String format = new DecimalFormat(& ...

  2. selenium让人摸不着头脑的问题

    selenium让人摸不着头脑的问题 问题一 使用webdriver驱动firefox浏览器时如果不设置参数,默认使用的Firefox的profile和平时打开浏览器使用的firefox不一样,如果要 ...

  3. libevent安装总结 - jinfg2008的专栏 - 博客频道 - CSDN.NET

    libevent安装总结 - jinfg2008的专栏 - 博客频道 - CSDN.NET libevent安装总结 分类: linux 系统配置 2013-02-13 22:37 99人阅读 评论( ...

  4. cocos2dx使用tolua关于字符串处理的一个问题

    正在使用cocos2dx的tolua binding在此过程中发现的一个问题.假设一回或输入是std::string当我们不同意包括二进制数据,和std::string我同意,这样一来就导致了不正确的 ...

  5. ContentType ,charset和pageEncoding的区别(转)

    ========================说法一=========================== ContentType 属性指定响应的 HTTP 内容类型.如果未指定 ContentTy ...

  6. Mongodb数据备份恢复

    Mongodb数据备份恢复 一.MongoDB数据库导入导出操作 1.导出数据库 twangback为备份的文件夹 命令: mongodump -h 127.0.0.1[服务器IP] -d advie ...

  7. Nagios+pnp4nagios+rrdtool 安装配置nagios被监控端NRPE配置(二)

    NRPE监控插件基础 NRPE总共由两部分组成: (1).check_nrpe插件,运行在监控主机上. (2).NRPE daemon,运行在远程的linux主机上(通常就是被监控机) 整个的监控过程 ...

  8. js 自定义方法 实现停留几秒 sleep

    function sleep(numberMillis) { var now = new Date(); var exitTime = now.getTime() + numberMillis; wh ...

  9. Linux 命令 快捷命令综合

    FTP开机启动 启动要让FTP每次开机自动启动,运行命令:  chkconfig --level 35 vsftpd on linux 关机 1.halt linux 注销 1.logout linu ...

  10. Xamarin For Visual Studio 3.7.165 完整离线破解版

    原文 Xamarin For Visual Studio 3.7.165 完整离线破解版 Xamarin For Visual Studio就是原本的Xamarin For Android 以及 Xa ...