中国(北方)大学生程序设计训练赛(第一周) (D E)
2017-03-05 17:05
295 查看
比赛链接
D题是个二分,每次check复杂度为O(n),类似于xdu_1068,只是一个是求积,一个是求商
E——plus
D题是个二分,每次check复杂度为O(n),类似于xdu_1068,只是一个是求积,一个是求商
#include<iostream> #include<algorithm> #include<cstring> using namespace std; typedef long long LL; LL n,ans; const int N=6; const LL mod=1e9+7; LL b[]= {0,0,0,1,0,-1}; struct Mat { LL mat ; } A; Mat Mut(Mat a,Mat b) { Mat c; memset(c.mat,0,sizeof(c.mat)); for(int k=0; k<N; k++) for(int i=0; i<N; i++) for(int j=0; j<N; j++) { c.mat[i][j]+=a.mat[i][k]*b.mat[k][j]%mod; c.mat[i][j]=c.mat[i][j]%mod; } return c; } Mat Qpow(Mat a,LL n) { Mat c; for(int i=0; i<N; ++i) for(int j=0; j<N; ++j) c.mat[i][j]=(i==j); for(; n; n>>=1) { if(n&1) c=Mut(c,a); a=Mut(a,a); } return c; } LL cal(Mat A,LL n,LL b[]) { Mat A_=Qpow(A,n-1); LL ret=0; for(int i=0; i<N; i++) { ret+=A_.mat[1][i]*b[i]; ret%=mod; } return (ret+mod)%mod; } void init_A() { memset(A.mat,0,sizeof(A.mat)); A.mat[0][0]=1,A.mat[0][1]=1,A.mat[0][2]=1; A.mat[1][0]=1; A.mat[2][5]=1; A.mat[3][2]=1; A.mat[4][3]=1; A.mat[5][4]=1; } int main() { init_A(); while(cin>>b[1]>>b[0]>>n) //b[1]即f1,b[0]即f2 { ans=cal(A,n,b); cout<<ans<<endl; } }
E——plus
相关文章推荐
- 中国(北方)大学生程序设计训练赛(第一周)-F(线段树)
- 中国(北方)大学生程序设计训练赛(第一周)(Problem F: 等差区间-线段树+等差数列平方和公式)
- 中国(北方)大学生程序设计训练赛(第一周)(Problem D: 数学题-二分+双指针)
- 中国(北方)大学生程序设计训练赛(第一周)-A(生成树计数)
- 中国(北方)大学生程序设计训练赛(第一周)
- 等差区间(写的很脑残)——中国(北方)大学生程序设计训练赛(第一周)F
- 中国(北方)大学生程序设计训练赛(第一周)(Problem B: 埃蒙的时空航道-最小割转dp+贪心)
- 中国(北方)大学生程序设计训练赛(第一周)E. water problem
- 中国(北方)大学生程序设计训练赛(第一周)E. water problem
- 矩阵快速幂-中国(北方)大学生程序设计训练赛(第一周)Water Problem
- 中国(北方)大学生程序设计训练赛(第一周)-D (二分)
- 中国(北方)大学生程序设计训练赛(第一周)(Problem E: Water Problem-矩阵快速幂)
- 中国(北方)大学生程序设计训练赛(第二周)(Problem A: Common Substrings-hash)
- 中国(北方)大学生程序设计训练赛(第二周)(Problem B: A Boring Game-乱搞)
- 中国(北方)大学生程序设计训练赛(第二周) (A B D G)
- 中国(北方)大学生程序设计训练赛(第二周)(Problem C: A Water Problem-dp)
- 中国(北方)大学生程序设计训练赛(第二周)(Problem G: Connected Components-并查集)
- 中国(北方)大学生程序设计训练赛(第三周)(Interesting sequence-找规律)
- 中国(北方)大学生程序设计训练赛(第三周)(List likes playing card-期望)
- ACM/ICPC中国•辽宁省第二届大学生程序设计竞赛通知