http://acm.hdu.edu.cn/showproblem.php?pid=4686

当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂

Ai,Bi的递推式题目已经给出,

Ai*Bi=Ax*Bx*(Ai-1*Bi-1)+Ax*By*Ai-1+Bx*Ay*Bi-1+Ay*By

AoD(n)=AoD(n-1)+AiBi

构造向量I{AoD(i-1),Ai*Bi,Ai,Bi,1}

初始向量为I0={0,A0*B0,A0,B0,1}

构造矩阵A{

1,0,0,0,0,

1,Ax*Bx,0,0,0,
0,Ax*By,Ax,0,0,

0,Bx*Ay,0,Bx,0,

0,Ay*By,Ay,By,1,

}

则I0*(A)^n则为包含结果的向量,此时I[0]即为解答

注意:

1.据说有n=0,直接输出0

2.long long的使用

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll n,ao,bo,ax,bx,ay,by;
void init(ll** ans,ll** base){
fill(ans[0],ans[0]+5,0);
fill(base[0],base[0]+25,0);
ans[0][1]=ao*bo%mod;
ans[0][2]=ao;
ans[0][3]=bo;
ans[0][4]=1;
base[0][0]=1;
base[1][0]=1;base[1][1]=ax*bx%mod;
base[2][1]=ax*by%mod;base[2][2]=ax;
base[3][1]=bx*ay%mod;base[3][3]=bx;
base[4][1]=ay*by%mod;base[4][2]=ay;base[4][3]=by;base[4][4]=1;
}
void print(ll **t ,int m,int r){
for(int i=0;i<m;i++){
for(int j=0;j<r;j++){
printf("%I64d ",t[i][j]);
}
puts("");
}
} void multi(ll** t,ll** b,ll ** tmp,int m,int r,int s){
fill(tmp[0],tmp[0]+m*s,0);
for(int i=0;i<m;i++){
for(int j=0;j<s;j++){
for(int k=0;k<r;k++){
tmp[i][j]+=(t[i][k]*b[k][j])%mod;
tmp[i][j]%=mod;
}
}
}
} void qpow(ll** ans,ll ** base,ll**tmp,ll time,int r,int m){
while(time>0){
if(time&1){
multi(ans,base,tmp,r,m,m);
copy(tmp[0],tmp[0]+r*m,ans[0]);
time--;
}
multi(base,base,tmp,m,m,m);
copy(tmp[0],tmp[0]+m*m,base[0]);
time>>=1;
}
} int main(){
ll ** ans = new ll*[1],**tmp=new ll*[5],** base =new ll*[5];
ans[0]=new ll[5],tmp[0]=new ll[25],base[0]=new ll[25];
for(int i=1;i<5;i++){
tmp[i]=tmp[0]+5*i;
base[i]=base[0]+5*i;
}
while(scanf("%I64d",&n)==1){
scanf("%I64d%I64d%I64d",&ao,&ax,&ay);
ao%=mod;ax%=mod;ay%=mod;
scanf("%I64d%I64d%I64d",&bo,&bx,&by);
bo%=mod;bx%=mod;by%=mod;
if(n==0)puts("0");
else {
init(ans,base);
qpow(ans,base,tmp,n,1,5);
printf("%I64d\n",ans[0][0]);
} }
delete ans;delete base;delete tmp;
return 0;
}

  

HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1的更多相关文章

  1. hdu 4686 Arc of Dream(矩阵快速幂)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 其中a0 = A0ai = ai-1*AX+AYb0 = B0bi = bi-1*BX+BY ...

  2. hdu 4686 Arc of Dream_矩阵快速幂

    题意:略 构造出矩阵就行了 |   AX   0    AXBY   AXBY       0  |                                                   ...

  3. HDU4686 Arc of Dream 矩阵快速幂

    Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  4. 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 ...

  5. S - Arc of Dream 矩阵快速幂

    An Arc of Dream is a curve defined by following function: where a 0 = A0 a i = a i-1*AX+AY b 0 = B0  ...

  6. hdu----(4686)Arc of Dream(矩阵快速幂)

    Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  7. HDOJ 4686 Arc of Dream 矩阵高速幂

    矩阵高速幂: 依据关系够建矩阵 , 高速幂解决. Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/ ...

  8. HDU 4686 Arc of Dream(矩阵)

    Arc of Dream [题目链接]Arc of Dream [题目类型]矩阵 &题解: 这题你做的复杂与否很大取决于你建的矩阵是什么样的,膜一发kuangbin大神的矩阵: 还有几个坑点: ...

  9. HDU4686 Arc of Dream —— 矩阵快速幂

    题目链接:https://vjudge.net/problem/HDU-4686 Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memo ...

随机推荐

  1. Git 进阶之底层相关

    Git is a content-addressable filesystem. 1. Plumbing 和 Porcelain "Plumbing commands": Git ...

  2. Squirrel语言初探(可以使用VC6或者MinGW编译)

    Squirrel语言初探 为啥我要关注Squirrel语言?原来Squirrel就很像我希望设计出的理想中的语言(当然也不完全符合).比如我觉得Lua的语法表述不清晰,累赘,于是想用C系语法来代替Lu ...

  3. 数据块加密模式以及IV的意思

    (本文资料主要来自:http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation) 目前流行的加密和数字认证算法,都是采用块加密(block ...

  4. 查T结果与Z结果的P值[转载]

    T检验P值表格来自:https://blog.csdn.net/m0_37777649/article/details/74937242 Z检验表格来自:https://wenku.baidu.com ...

  5. What do you think the coming adidas NMD Singapore

    adidas NMD Singapore is surprising everybody with a lot of completely new NMD choices combined with ...

  6. cocos进阶教程(5)CC_CALLBACK_X系列的使用技巧

    CC_CALLBACK_1,CC_CALLBACK_2,CC_CALLBACK_3 这些都是std::bind的宏,数字1,2,3主要表示要占位的数量,也是将来传递参数的数量. // new call ...

  7. Codeforces Round #523 (Div. 2) Solution

    A. Coins Water. #include <bits/stdc++.h> using namespace std; int n, s; int main() { while (sc ...

  8. map.containsKey

    该方法判断Map集合对象中是否包含指定的键名.如果Map集合中包含指定的键名,则返回true,否则返回false. 语法  containsKey(Object key) . e.g public s ...

  9. 《Java入门第二季》第一章 类和对象

    什么是类和对象 如何定义 Java 中的类 如何使用 Java 中的对象 Java中的成员变量和局部变量1.成员变量:在类中定义,描述构成对象的组件. 2.局部变量:在类的方法中,用于临时保存数据. ...

  10. 课堂练习——Hash 20162305

    课堂练习--Hash 20162305 课堂练习要求 利用除留余数法为下列关键字集合的存储设计hash函数,并画出分别用开放寻址法和拉链法解决冲突得到的空间存储状态(散列因子取0.75) 关键字集合: ...