Chang'an(YY's problem-矩阵乘法)
2015-04-24 19:13
405 查看
矩阵乘法
#include <bits/stdc++.h> #define LL long long #define MOD 1000000007 using namespace std; LL MMM(int a, int b) { return ((a%MOD)*(LL)(b%MOD))%MOD; } LL x[4], a[4], t[4]; LL* mult(LL *a,LL *b) { x[0]=MMM(a[0],b[0])+MMM(a[1],b[2]); x[0]%=MOD; x[1]=MMM(a[0],b[1])+MMM(a[1],b[3]); x[1]%=MOD; x[2]=MMM(a[2],b[0])+MMM(a[3],b[2]); x[2]%=MOD; x[3]=MMM(a[2],b[1])+MMM(a[3],b[3]); x[3]%=MOD; return x; } void print(LL *a) { cout<<a[0]<<" "<<a[1]<<endl; cout<<a[2]<<" "<<a[3]<<endl; } LL e[4]={1,0,0,1}; LL s[4]={0,-1,1,1}; void eq(LL *a,LL *b) { for (int i=0;i<4;i++) a[i]=b[i]; } int main() { int T, p; long long f1, f2; cin>>T; for(int I=1; I<=T; I++){ cin>>f1>>f2; cin>>p;p--; eq(t, s); if (p%2==0){ eq(a, e); } else { eq(a, t); } p=p>>1; while (p>0) { eq(t,mult(t,t)); if (p%2==1){eq(a,mult(a,t));} p=p>>1; } long long ans = ((f1*a[0]+MOD)%MOD + (f2*a[2]+MOD)%MOD+MOD)%MOD; if (ans<0) {cout<<ans+MOD<<endl; }else{cout<<ans<<endl;} } return 0; }
相关文章推荐
- Chang'an(YY's string-模拟)
- Chang'an(Palindrome Numbers-回文数字统计)
- Chang'an(Black Box-线段树)
- hdoj 3521 An easy Problem(矩阵乘法)
- Redeploy' has encountered a problem.An internal error occurred during
- 'SVN更新' has encountered a problem :An internal error occurred during: svn错误
- Chang'an(Hack-01分数规划)
- hdu 5015 233 Matrix 2014 ACM/ICPC Asia Regional Xi'an Online 矩阵快速幂
- FOJ 1617 Hero's matrix(矩阵乘法,将3次方复杂度变为二次方)
- Chang'an(Dance Party-贪心)
- Rodrigues' Rotation Matrix(罗德里格旋转矩阵)
- The value of attribute "description" associated with an element type "target" must not contain the '<' character.
- toncat报错-->'Start Tomcat v8.0 Server at localhost' has encountered a problem.
- How to control your dust collection with an Arduino (it's easy)
- hdu 5014 Number Sequence 2014 ACM/ICPC Asia Regional Xi'an Online 数论
- UVA 10026 Shoemaker's Problem 鞋匠的难题 贪心+排序
- Pods was rejected as an implicit dependency for 'libPods.a' because its architectures 'x86_64' didn
- net.sf.json.JSONException: 'object' is an array. Use JSONArray instead
- The project was not built due to "Could not delete ''.". Fix the problem, then try refreshing this p
- codeforces 459D - Pashmak and Parmida's problem【离散化+处理+逆序对】