HDU 4686 Arc of Dream(递归矩阵加速)
标题效果:你就是给你一程了两个递推公式公式,第一个让你找到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

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?
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.
1
1 2 3
4 5 6
2
1 2 3
4 5 6
3
1 2 3
4 5 6
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(递归矩阵加速)的更多相关文章
- hdu 4686 Arc of Dream(矩阵快速幂乘法)
Problem Description An Arc of Dream is a curve defined by following function: where a0 = A0 ai = ai- ...
- HDU 4686 Arc of Dream (矩阵快速幂)
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4686 Arc of Dream(矩阵)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 思路: #include <iostream>#include <cs ...
- HDU 4686 Arc of Dream(矩阵)
Arc of Dream [题目链接]Arc of Dream [题目类型]矩阵 &题解: 这题你做的复杂与否很大取决于你建的矩阵是什么样的,膜一发kuangbin大神的矩阵: 还有几个坑点: ...
- 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 ...
- 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 ...
- HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...
- HDU 4686 Arc of Dream(快速幂矩阵)
题目链接 再水一发,构造啊,初始化啊...wa很多次啊.. #include <cstring> #include <cstdio> #include <string&g ...
- 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 ...
随机推荐
- liunx清理磁盘du -h --max-depth=1 /data/*
liunx清理磁盘du -h --max-depth=1 /data/*
- hdu3033(变形分组背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3033 题意:Iserlohn要买鞋,有k种牌子,每种牌子至少买一双鞋子.每双鞋子有标价跟实际价值.求用 ...
- struts2第一个程序的详解(配图)
首先我们在struts2中要写上一个action <packagename="fish"namespace="/test"extends="st ...
- Linux lamp环境编译安装
1.安装准备: 1)httpd-2.0.52.tar.gz 2)mysql-4.1.12.tar.gz 3)libxml2-2.6.27.tar 4)freetype-2.1.10.tar 5)gd- ...
- 美版SOLOWHEEL与盗版SOLOWHEEL-IPS独轮车终极PK【图】_厂商资讯_太平洋电脑网
http://g.pconline.com.cn/x/330/3304676.html
- Android网络服务发现(NSD)协议的使用
Android的网络服务发现协议(NSD)能够用于在小范围的网络中发现邻近设备上的某个应用.这对于一些社交网络.多人游戏类的应用会很有帮助. Android的NSD的用法大致上分为四种操作: 1. 注 ...
- 让ecshop显示商品销量或者月销量
首先,ecshop的信息显示模块在. ./includes/lib_goods.php文件 在其末尾添加下面这个函数 月销量:(和总销量二选一) function ec_buysum($goods_i ...
- Cocos2d-x学习笔记(1)
Cocos2d-x原型Cocos2d,基于Cocos2d-iPhone,跨平台. Hello Workd分析: 1."resource"目录 该目录主要用于存放游戏中须要的图片.音 ...
- Windows Phone开发(33):路径之其它Geometry
原文:Windows Phone开发(33):路径之其它Geometry 上一节中,我们把最复杂的PathGeometry给干了,生剩下几个家伙就好办事了.一起来见见他们的真面目吧. 一.LineGe ...
- mysql 触发器和存储过程组合使用,实现定时触发操作
mysql可以实现定时触发功能,比如说定于某某时间mysql数据库做什么工作,或每隔多长时间做什么工作. 第二种情况应用还是比较广的,比如说我希望每天检查一下我的数据信息,超过一个月的无用信息清除以腾 ...