hdu4686矩阵快速幂
花了一个多小时终于ac了,有时候真的是需要冷静一下重新打一遍才行。
这题就是 |aod(n)| = |1 ax*bx ax*by ay*bx by*ay| |aod(n-1) |
|an*bn | = |0 ax*bx ax*by ay*bx by*ay| |an-1*bn-1 |
|an | = |0 0 ax 0 ay | | a(n-1) |
|bn | = |0 0 0 bx by | | b(n-1) |
|1 | = |0 0 0 0 1 | | 1 |
然后特判n==0的情况就行了
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=<<+,inf=0x3f3f3f3f; struct Node{
ll row,col;
ll a[N][N];
};
Node mul(Node x,Node y)
{
Node ans;
ans.row=x.row,ans.col=y.col;
memset(ans.a,,sizeof ans.a);
for(ll i=;i<x.row;i++)
for(ll j=;j<x.col;j++)
for(ll k=;k<y.col;k++)
ans.a[i][k]=(ans.a[i][k]+x.a[i][j]*y.a[j][k])%mod;
return ans;
}
Node quick_mul(Node x,ll n)
{
Node ans;
ans.row=x.row,ans.col=x.col;
memset(ans.a,,sizeof ans.a);
for(ll i=;i<ans.col;i++)ans.a[i][i]=;
while(n){
if(n&)ans=mul(ans,x);
x=mul(x,x);
n>>=;
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
// cout<<setiosflags(ios::fixed)<<setprecision(2);
ll n,a0,b0,ax,ay,bx,by;
while(cin>>n>>a0>>ax>>ay>>b0>>bx>>by){
if(n==)
{
cout<<<<endl;
continue;
}
Node A;
A.row=,A.col=;
memset(A.a,,sizeof A.a);
A.a[][]=A.a[][]=;
A.a[][]=A.a[][]=ax*bx%mod;
A.a[][]=A.a[][]=ax*by%mod;
A.a[][]=A.a[][]=ay*bx%mod;
A.a[][]=A.a[][]=ay*by%mod;
A.a[][]=ax,A.a[][]=ay;
A.a[][]=bx,A.a[][]=by;
A=quick_mul(A,n-);
Node B;
B.row=,B.col=;
B.a[][]=B.a[][]=a0*b0%mod,B.a[][]=a0,B.a[][]=b0,B.a[][]=;
B=mul(A,B);
cout<<B.a[][]%mod<<endl;
}
return ;
}
hdu4686矩阵快速幂的更多相关文章
- 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 ...
- hdu4686 简单的矩阵快速幂求前n项和
HDU4686 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意:题目说的很清楚了,英语不好的猜也该猜懂了,就是求一个表达式的前n项和,矩阵 ...
- hdu4686 Arc of Dream ——构造矩阵+快速幂
link: http://acm.hdu.edu.cn/showproblem.php?pid=4686 构造出来的矩阵是这样的:根据题目的ai * bi = ……,可以发现 矩阵1 * 矩阵3 = ...
- HDU4686 Arc of Dream 矩阵快速幂
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)
题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...
- 51nod 算法马拉松18 B 非010串 矩阵快速幂
非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...
- 51nod 1113 矩阵快速幂
题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...
- 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】
还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...
- HDU5950(矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:f(n) = f(n-1) + 2*f(n-2) + n^4,f(1) = a , f(2 ...
随机推荐
- Intellij idea的Dependencies波浪线
昨天在家做项目不知道搞了什么出现了大量波浪线.搞了大半天解决了下面的问题. 1.pom.xml出现波浪线.看右边 maven project-->Profiles 勾选dev 2.上面已勾选还有 ...
- arc 和 非arc兼容
1,选择项目中的Targets,选中你所要操作的Target, 2,选Build Phases,在其中Complie Sources中选择需要ARC的文件双击, 并在输入框中输入:-fobjc-arc ...
- git-【四】撤销修改和删除文件操作
一:撤销修改: 比如我现在在readme.txt文件里面增加一行 内容为555555555555,我们先通过命令查看如下: 在未提交之前,发现添加5555555555555内容有误,所以得马上恢复以前 ...
- [Axiom3D]第一个Axiom3D程序
Axiom3D程序的基本渲染流程 #region Namespace Declarations using System; using System.Linq; using Axiom.Core; u ...
- Spark提交应用程序之Spark-Submit分析
1.提交应用程序 在提交应用程序的时候,用到 spark-submit 脚本.我们来看下这个脚本: if [ -z "${SPARK_HOME}" ]; then export S ...
- Android开发新手问题
因为最近在用空闲时间学习Android开发,期间确实遇到了一些问题.而且因为我之前在公司里一直都是在使用Eclipse进行开发,所以最初我学习Android时也就选择了Google的包含android ...
- Python ImportError: DLL load failed: %1 不是有效的 Win32 应用程序。
问题怎么出现的: 电脑是win8 64位,,下载了一个mysqldb 32位,http://sourceforge.net/projects/mysql-python/files/latest/dow ...
- PHP error_reporting() 错误控制函数功能详解
定义和用法:error_reporting() 设置 PHP 的报错级别并返回当前级别. 函数语法:error_reporting(report_level) 如果参数 level 未指定,当前报错级 ...
- VS2010/MFC编程入门之二十二(常用控件:按钮控件Button、Radio Button和Check Box)
言归正传,鸡啄米上一节中讲了编辑框的用法,本节继续讲解常用控件--按钮控件的使用. 按钮控件简介 按钮控件包括命令按钮(Button).单选按钮(Radio Button)和复选框(Check Box ...
- node学习笔记第一天
ES6---* JavaScript语言随着使用的人越来越多,ECMA语法规范:if/else* 为了让js语言更适应大型应用的开发.旨在消除一些怪异的行为 ### 包含内容(strict严格模式)- ...