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. [dpdk] TSC , HPET, Timer, Event Timer,RDTSCP

    关于dpdk timer跨越CPU core调度的准确性问题 首先dpdk的timer接口里边使用 cpu cycle来比较时间.根据之前的内容 [dpdk] dpdk --lcores参数 当一个E ...

  2. Runloop, 多线程

    Runloop是个死循环,为甚么? 1. 保证程序不退出 2.监听用户的事件, 触摸,时钟,网络事件 UITrackingMode,只能触摸事件,没有触摸事件了,直接就停止了 Runloop: sou ...

  3. Java之旅_高级教程_网络编程

    摘自:http://www.runoob.com/java/java-networking.html JAVA网络编程 网络编程是指编写运行在多个设备(计算机)的程序,这些设备都通过网络连接起来. j ...

  4. linux crypt()函数使用总结

    原型: char *crypt(const char *key, const char *salt); 标准说明: crypt()算法会接受一个最长可达8字符的密钥(即key),并施以数据加密算法(D ...

  5. byte数组存储到mysql

    public int AddVeinMessage(byte[] data)//插入数据库 { using (BCSSqlConnection = new MySqlConnection(strCon ...

  6. Postfix 邮件服务器搭建

    搭建服务环境: Centos 6 配置域名hosts: mail.demonC6.com 1.清理系统自带的邮件软件 # rpm -qa | grep sendmail* # rpm -e sendm ...

  7. Code once, debug everywhere.

    1.通常语言调用一个函数会出exception的情况,在javascript里面返回的是undefined.等到程序运行不正常的时候,你看到数据结构的有些地方为什么是undefined,只能哭了. 2 ...

  8. linux 查看磁盘读写:iostat

    iostat命令用来查看磁盘IO的读写情况,用法如下: 安装iostat命令 [root@mysql ~]# yum install -y sysstat [root@mysql ~]# iostat ...

  9. 别让Open Sans字体拖慢wordpress后台速度

    最近打开wordpress后台是不是很慢?国内GG登不上了?这两者有没什么直接的联系?没错,WordPress后台是自动加载的谷歌Open Sans字体,据说gg服务器已经迁移到阿嘛丽可,需要一些小手 ...

  10. Fast-R-CNN

    基于R-CNN和SPP-Net思想,RBG提出了Fast-R-CNN算法.如果选用VGG16网络进行特征提取,在训练阶段,Fast-R-CNN的速度相比RCNN和SPP-Net可以分别提升9倍和3倍: ...