Arc of Dream

【题目链接】Arc of Dream

【题目类型】矩阵

&题解:

这题你做的复杂与否很大取决于你建的矩阵是什么样的,膜一发kuangbin大神的矩阵:



还有几个坑点:当n是0 输出0;建矩阵时是相乘的一定要取模M,因为如果不取模最大的情况是1e9*2e9*2e9,爆long long 这块坑了我好长时间.

&代码:

#include <cstdio>
#include <bitset>
#include <iostream>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
const int M= 1e9 +7;
ll n,a0,ax,ay,b0,bx,by;
struct mat
{
ll m[8][8];
}A;
ll tb[8];
void Init()
{
tb[0]=a0,tb[1]=b0,tb[2]=a0*b0%M,tb[3]=a0*b0%M,tb[4]=1;
memset(A.m,0,sizeof(A.m));
A.m[0][0]=ax,A.m[4][0]=ay;
A.m[1][1]=bx,A.m[4][1]=by;
A.m[0][2]=ax*by%M,A.m[1][2]=ay*bx%M,A.m[2][2]=ax*bx%M,A.m[4][2]=ay*by%M;
for(int i=0;i<5;i++) A.m[i][3]=A.m[i][2];
A.m[3][3]=A.m[4][4]=1;
}
//debug
void DF()
{
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
printf("%4lld ",A.m[i][j]);
}
cout<<endl;
}
}
mat Mul(mat a,mat b)
{
mat c;
for(int i=0;i<5;i++)
for(int j=0;j<5;j++){
c.m[i][j]=0;
for(int k=0;k<5;k++){
c.m[i][j]=(c.m[i][j]+a.m[i][k]*b.m[k][j])%M;
}
}
return c;
}
mat bPow(mat a,ll z)
{
mat un;
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
un.m[i][j]=(i==j);
while(z){
if(z&1)
un=Mul(un,a);
a=Mul(a,a);
z>>=1;
}
return un;
}
int main()
{
// ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
//("E:1.txt","r",stdin);
while(cin>>n){
cin>>a0>>ax>>ay;
cin>>b0>>bx>>by;
Init();
if(n>0){
A=bPow(A,n-1);
}
else{
cout<<0<<endl;
continue;
}
// DF();
ll ans=0;
for(int i=0;i<5;i++){
ans=(ans+A.m[i][3]*tb[i])%M;
}
cout<<ans%M<<endl;
}
return 0;
}

HDU 4686 Arc of Dream(矩阵)的更多相关文章

  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 矩阵快速幂,线性同余 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...

  3. hdu 4686 Arc of Dream(矩阵快速幂乘法)

    Problem Description An Arc of Dream is a curve defined by following function: where a0 = A0 ai = ai- ...

  4. HDU 4686 Arc of Dream(递归矩阵加速)

    标题效果:你就是给你一程了两个递推公式公式,第一个让你找到n结果项目. 注意需要占用该公式的复发和再构造矩阵. Arc of Dream Time Limit: 2000/2000 MS (Java/ ...

  5. HDU 4686 Arc of Dream (2013多校9 1001 题,矩阵)

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

  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(矩阵)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 思路: #include <iostream>#include <cs ...

  9. HDU 4686 Arc of Dream(快速幂矩阵)

    题目链接 再水一发,构造啊,初始化啊...wa很多次啊.. #include <cstring> #include <cstdio> #include <string&g ...

随机推荐

  1. 【数论】Prime Time UVA - 10200 大素数 Miller Robin 模板

    题意:验证1~10000 的数 n^n+n+41 中素数的个数.每个询问给出a,b  求区间[a,b]中质数出现的比例,保留两位 题解:质数会爆到1e8 所以用miller robin , 另外一个优 ...

  2. php之print_r

    stdClass类是PHP的一个内部保留类,初始时没有成员变量也没有成员方法,所有的魔术方法都被 设置为null,可以使用其传递变量参数,但是没有可以调用的方法.stdClass类可以被继承. 只是这 ...

  3. [hardware][intel] intel全系列网卡调研

    除了公司用,我自己还要买一块家用. 但是在这一切开始之前,还需要搞清楚PCIE到底咋回事. 一, 总线 https://zh.wikipedia.org/wiki/%E6%80%BB%E7%BA%BF ...

  4. rman checksyntax和解决RMAN-01009: syntax error: found "dot"

    在日常清归档时候执行脚本报错 RMAN-00552: syntax error in command line argumentsRMAN-01009: syntax error: found &qu ...

  5. linux strncpy()和strcat使用总结

    strcat原型:char *strcat(char *dest,const char *src); 把src所指字符串添加到dest结尾处(覆盖dest结尾处的'\0')并添加'\0'.src和de ...

  6. 【PyQt5-Qt Designer】Qt 的标准对话框总结

    PyQt5 各种弹出对话框的总结 忙碌了两天才总结完,深刻体会到 “编程在实践中才能领悟更深”,后续有了更多的 理解继续来补充... 效果如下: 参考: https://www.cnblogs.com ...

  7. 20180310 KindEditor 富文本编辑器

    问题: 如何判断富文本编辑器文本内容非空 错误的办法,采用js 对控件本身的txt ID 号抓取获取值,由于加载富文本编辑器时,界面的ID 已经经过了修改或者可以用转换来说,所以抓取是无效果的. 需要 ...

  8. kafka4 副本机制

    概述 每个分区有n个副本,可以承受n-1个节点故障. 每个副本都有自己的leader,其余都是follower. zk中存放分区的leader和 follower replica的信息.(get /b ...

  9. test TSS Work about

     activity01   activity02   FamilyNew   workTest

  10. select 数字/字符串/count(参数)/sum(数字) from table

    第一种的写法是增加临时列,每行的列值是写在select后的数: --1select 1 from W_EC_PLACESTATION_COLLECT t--2select 2 from W_EC_PL ...