HDU-4686 Arc of Dream 构造矩阵
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686
因为ai = ai-1*AX+AY ,bi = bi-1*BX+BY ,那么ai*bi=AX*BX*A*ai-1*bi-1+AX*BY*ai-1+BX*AY*bi-1+AY*BYAY。令Sn为ai*bi前n项的和,Sn=Sn-1 + an*bn,因此我们可以构造一个如下的转移矩阵:
然后矩阵乘法优化就可以了。。。
注意此题n=0的情况!
其实矩阵大小只要5就可以了,那几个常数项可以合并到一列。。。
//STATUS:C++_AC_1296MS_232KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End LL n,a0,ax,ay,b0,bx,by; const int size=; struct Matrix{
LL ma[size][size];
Matrix friend operator * (const Matrix a,const Matrix b){
Matrix ret;
mem(ret.ma,);
int i,j,k;
for(i=;i<size;i++)
for(j=;j<size;j++)
for(k=;k<size;k++)
ret.ma[i][j]=(ret.ma[i][j]+a.ma[i][k]*b.ma[k][j]%MOD)%MOD;
return ret;
}
}A; Matrix mutilpow(LL k)
{
int i;
Matrix ret;
mem(ret.ma,);
for(i=;i<size;i++)
ret.ma[i][i]=;
for(;k;k>>=(1LL)){
if(k&(1LL))ret=ret*A;
A=A*A;
}
return ret;
} int main(){
// freopen("in.txt","r",stdin);
int i,j;
LL ans;
LL B[size];
Matrix F;
while(~scanf("%I64d",&n))
{
scanf("%I64d%I64d%I64d",&a0,&ax,&ay);
scanf("%I64d%I64d%I64d",&b0,&bx,&by);
if(n==){printf("0\n");continue;} a0%=MOD;ax%=MOD;ay%=MOD;
b0%=MOD;bx%=MOD;by%=MOD;
mem(A.ma,);
A.ma[][]=A.ma[][]=;
A.ma[][]=ax;A.ma[][]=ay;
A.ma[][]=;
A.ma[][]=bx;A.ma[][]=by;
A.ma[][]=;
A.ma[][]=ax*by%MOD;A.ma[][]=bx*ay%MOD;A.ma[][]=ax*bx%MOD;A.ma[][]=ay*by%MOD;
A.ma[][]=;
F=mutilpow(n-);
B[]=a0*b0%MOD;
B[]=(a0*ax%MOD+ay)%MOD;B[]=;
B[]=(b0*bx%MOD+by)%MOD;B[]=;
B[]=B[]*B[]%MOD;B[]=;
ans=;
for(i=;i<size;i++){
ans=(ans+F.ma[][i]*B[i]%MOD)%MOD;
} printf("%I64d\n",ans);
}
return ;
}
HDU-4686 Arc of Dream 构造矩阵的更多相关文章
- hdu 4686 Arc of Dream(矩阵快速幂乘法)
Problem Description An Arc of Dream is a curve defined by following function: where a0 = A0 ai = ai- ...
- HDU 4686 Arc of Dream (矩阵快速幂)
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4686 Arc of Dream(矩阵)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 思路: #include <iostream>#include <cs ...
- HDU 4686 Arc of Dream(递归矩阵加速)
标题效果:你就是给你一程了两个递推公式公式,第一个让你找到n结果项目. 注意需要占用该公式的复发和再构造矩阵. Arc of Dream Time Limit: 2000/2000 MS (Java/ ...
- HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...
- 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 ...
- HDU 4686 Arc of Dream(矩阵)
Arc of Dream [题目链接]Arc of Dream [题目类型]矩阵 &题解: 这题你做的复杂与否很大取决于你建的矩阵是什么样的,膜一发kuangbin大神的矩阵: 还有几个坑点: ...
- hdu 4686 Arc of Dream
思路:构造矩阵 a[i]*b[i]=ax*bx*a[i-1]*b[i-1]+ax*by*a[i-1]+ay*bx*b[i-1]+ay*by 代码如下: #include<iostream> ...
- 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 ...
- HDU 4686 Arc of Dream(快速幂矩阵)
题目链接 再水一发,构造啊,初始化啊...wa很多次啊.. #include <cstring> #include <cstdio> #include <string&g ...
随机推荐
- codeforces #313 div1 B
模拟判定就可以了 判定字符串是否相等用hash来判断 QAQ 值得一提的是一开始我交的时候T了 结果我将递归的顺序调整了一下就A了 (并不知道为什么 #include<cstdio> #i ...
- CentOS7.1配置远程桌面
网上看了很多资料,完全是乱的. 我使用的是CentOS7.1的系统.我的要求是windows的客户机可以远程访问CentOS系统. 1,首先需要检查一下服务器是否已经安装了VNC服务,检查服务器的是否 ...
- Linux下Keepalived 安装与配置
Keepalived 安装与配置 一.环境说明 1.操作系统内核版本:2.6.9-78.ELsmp 2.Keepalived软件版本:keepalived-1.1.20.tar.gz 二.环境配置 1 ...
- Java的类演进过程
1.从面向过程到面向对象 在大家最熟悉的C语言中,如果要定义一个复杂的数据类型就用结构体(Struct)来实现,而为结构体的每个操作都定义一个函数,这个函数与结构体本身的定义没有任何关系.程序的重心集 ...
- 【HDOJ】1914 The Stable Marriage Problem
稳定婚姻问题,Gale-Shapley算法可解. /* 1914 */ #include <iostream> #include <sstream> #include < ...
- 菜单练习-关机&取消
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> voi ...
- WP8触摸感应Manipulation的操作
触控感应不同事件的处理: 可将以下三个事件,绑定到一个控件中. /// <summary> /// 触摸开始事件 /// </summary> /// <param na ...
- Spring3中用注解直接注入properties中的值
在bean(可是controller, service, dao等了)中,使用@Value注解: @Service public class TestService{ @Value("${s ...
- iOS application: how to clear notifications?
http://stackoverflow.com/questions/8682051/ios-application-how-to-clear-notifications up vote105down ...
- oracle11g dataguard部署指南
一.Oracle11DB+DG配置 1. 单机环境介绍(PRIMARY DATABASE) 主库 primary public ip 192.168.0.252 ...