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. [No000012D]WPF(5/7)依赖属性

    介绍 WPF带来了很多传统 Windows 应用程序没有的新特性和选择.我们已经讨论了一些 WPF 的特性,是时候更进一步介绍其他特性了.当你读完这个系列之前的文章,我希望你已经或多或少地了解了 WP ...

  2. [No0000DC]C# FileHelper 本地文件、文件夹操作类封装FileHelper

    using System; using System.Diagnostics; using System.IO; using System.Text; using Shared; namespace ...

  3. [administrator][driver] driverctl 是如何在udev上层管理设备驱动的

    https://gitlab.com/driverctl/driverctl driverctl 处于 kernel 与 udev做设备与驱动管理的上层. 理解什么叫override是本文的核心内容. ...

  4. JAVA常用的异常处理情况

    从编程到现在,遇见过很多次程序崩的情况,好多时候都不知道怎么去解决才好,一般性解决就是百度或者问别人,但是每一次百度解决的下一次还是会遇见同样的问题,也没有系统的整理梳理过相关的处理异常的知识,再一次 ...

  5. django2.0内置分页

    #导入分页器from django.core.paginator import Paginator 1视图逻辑 #读取数据库 res = Product.objects.all() #建立分页器对象 ...

  6. Linux snprintf使用总结

    snprintf()函数用于将格式化的数据写入字符串,其原型为:    int snprintf(char *str, int n, char * format [, argument, ...]); ...

  7. 如何解决selenium打开chrome提示chromedriver.exe已停止工作

    场景:启动Chrome,打开URL,提示“disconnected: unable to connect to renderer” 解决方法:chromedriver与chrome的对应关系表, 需要 ...

  8. PHP三种运行方式(转载)

    三种运行方式:mod_php5.cgi.fast-cgi 1. 通过HTTPServer内置的模块来实现, 例如Apache的mod_php5,类似的Apache内置的mod_perl可以对perl支 ...

  9. SpringBoot-区分不同环境配置文件

    spring.profiles.active=pre application-dev.properties:开发环境 application-test.properties:测试环境 applicat ...

  10. 003-pro ant design 前端权限处理-支持URL参数的页面

    前天需要增加MD5引用 https://www.bootcdn.cn/blueimp-md5/ 1.修改权限文件(CheckPermissions.js)使用自定义权限 2.配置异常页面 2.1.创建 ...