hdu-4686 Arc of Dream
来源:互联网 发布:sem和seo区别aso 编辑:程序博客网 时间:2024/05/17 22:59
http://acm.hdu.edu.cn/showproblem.php?pid=4686
题意:已知a0,ax,ay a[i] = ax * a[i-1] + ay;
b0,bx,by b[i] = bx * b[i-1] + by;
求 ai*bi(0 < i <(n-1)) 的和;
ac代码:
/***设前n想和为sum[n],则:* a[n]*b[n] = a[n-1]*b[n-1]*ax*bx + a[n-1]*ax*by + b[n-1]*ay*bx + ay * by;** * { 1 0 0 0 0 }* { ax*bx ax*bx 0 0 0 }*{sum[n],a[n-1]*b[n-1],a[n-1],b[n-1],1} = {sum[n-1],a[n-2]*b[n-2],a[n-1],b[n-2],1}*{ ax*by ax*by ax 0 0 }* { ay*bx ay*bx 0 bx 0 }* { ay*by ay*by ay by 1 }*****/#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;typedef __int64 LL;#define mod 1000000007struct Z{ LL m[5][5]; Z(){ memset(m,0,sizeof(m)); } void init(){ for(int i = 0;i < 5;i++) m[i][i] = 1; }};Z operator * (Z a, Z b){ Z c; for(int i = 0;i < 5;i++) for(int k = 0;k < 5;k++) for(int j = 0;j < 5;j++) c.m[i][j] = (c.m[i][j] + a.m[i][k]*b.m[k][j])%mod; return c;}Z Pow(Z a,LL x){ Z ret; ret.init(); while(x){ if(x & 1) ret = ret * a; a = a * a; x >>= 1; } return ret;}int main(){ LL n,a0,ax,ay,b0,bx,by; while(cin >> n) { cin >> a0 >> ax >> ay; cin >> b0 >> bx >> by; LL k = a0 * b0 % mod; if(n == 0){cout << 0 <<endl;continue;} Z s; s.m[0][0] = 1; s.m[1][0] = ax*bx%mod;s.m[1][1] = ax*bx%mod; s.m[2][0] = ax*by%mod;s.m[2][1] = ax*by%mod;s.m[2][2] = ax%mod; s.m[3][0] = ay*bx%mod;s.m[3][1] = ay*bx%mod;s.m[3][3] = bx%mod; s.m[4][0] = ay*by%mod;s.m[4][1] = ay*by%mod;s.m[4][2] = ay%mod; s.m[4][3] = by%mod;s.m[4][4] = 1; s = Pow(s,n-1); LL ans = (s.m[0][0]*k + s.m[1][0]*k + s.m[2][0]*a0 + s.m[3][0]*b0 + s.m[4][0])%mod; cout << ans << endl; }}
0 0
- HDU 4686 Arc of Dream
- HDU 4686 Arc of Dream
- hdu 4686 Arc of Dream
- hdu 4686 Arc of Dream
- HDU 4686 Arc of Dream
- hdu-4686 Arc of Dream
- HDU 4686 Arc of Dream
- HDU 4686 Arc of Dream
- HDU 4686 Arc of Dream
- HDU 4686 Arc of Dream
- HDU 4686 Arc of Dream
- HDU Arc of Dream
- hdu-4686-Arc of Dream-矩阵
- hdu 4686Arc of Dream 杭电多校第九场1001 矩阵
- hdu 4686 Arc of Dream 多校第九场
- 多校 4686 Arc of Dream hdu 矩阵解
- hdu 4686 Arc of Dream(构造矩阵快速幂)
- hdu 4686 Arc of Dream 矩阵快速幂
- IOS学习 IOS8的UISearchBar对应
- js 快速转换成,(逗号)分割的字符串
- 跟着鸟哥学习Linux之文件与目录权限
- 捷克人垃圾污染
- 让运行更稳定 苹果ios 8将迎来首次更新
- hdu-4686 Arc of Dream
- 空间克隆健康接待客人季如风就开始
- ORACLE数据库常见问题汇总
- ubuntu系统debootstrap的使用
- 数据库SQL SELECT查询的工作原理
- 嵌入式 常见的undefined reference to涉及的链接问题
- 努比亚 Z5 mini刷机包 omni4.4.2修改V4.0 自用版 精简 MIUI特效
- debian软件源source.list文件格式说明
- Valid Number