HDU 4686 Arc of Dream
来源:互联网 发布:无锡软件测试培训 编辑:程序博客网 时间:2024/06/05 17:00
Problem Description
An Arc of Dream is a curve defined by following function:
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?
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?
Input
There are multiple test cases. Process to the End of File.
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.
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.
Output
For each test case, output AoD(N) modulo 1,000,000,007.
Sample Input
11 2 34 5 621 2 34 5 631 2 34 5 6
Sample Output
41341902
找到递推式,画出矩阵即可
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;typedef long long ll;const ll M=1e9+7;const ll size=6;ll a0,b0,ax,bx,ay,by,n;struct abc{ ll a[size][size]; abc(){ memset(a,0,sizeof(a));};};abc operator *(const abc &a,const abc &b){ abc c; for (int i=1;i<size;i++) for (int j=1;j<size;j++) for (int k=1;k<size;k++) { (c.a[i][k]+=a.a[i][j]*b.a[j][k])%=M; (c.a[i][k]+=M)%=M; } return c;}int main(){ while (cin>>n>>a0>>ax>>ay>>b0>>bx>>by) { if (n==0) {puts("0"); continue;} abc r,A; r.a[1][2]=(a0*ax+ay)%M; r.a[1][3]=(b0*bx+by)%M; r.a[1][1]=(r.a[1][2]*r.a[1][3])%M; r.a[1][4]=1; r.a[1][5]=(a0*b0)%M; A.a[1][1]=(ax*bx)%M; A.a[1][5]=1; A.a[2][1]=(ax*by)%M; A.a[2][2]=ax%M; A.a[3][1]=(ay*bx)%M; A.a[3][3]=bx%M; A.a[4][1]=(ay*by)%M; A.a[4][2]=ay%M; A.a[4][3]=by%M; A.a[4][4]=1; A.a[5][5]=1; for (--n;n>0;n>>=1) { if (n&1) r=r*A; A=A*A; } cout<<r.a[1][5]<<endl; } return 0;}
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 矩阵快速幂
- 逻辑运算注意的一点
- subsversion服务器安装方法
- 数据库基本特性
- HDU 2197本原串
- Nxn 矩阵旋转90度问题
- HDU 4686 Arc of Dream
- java学习之旅63常用类_包装类_Integer_Number_JDK源码分析
- spring jdbc 使用感想
- 20150718终于作了这个决定,写一篇实用的文章(自己测试过的装备/用品):
- svn权限配置方法
- MongoDB集群架构及搭建
- Leetcode #50 Pow(x, n)
- Android基础入门教程——1.1 背景相关与系统架构分析
- git使用简介