hdu4686 Arc of Dream ——构造矩阵+快速幂
link: http://acm.hdu.edu.cn/showproblem.php?pid=4686
构造出来的矩阵是这样的:根据题目的ai * bi = ……,可以发现 矩阵1 * 矩阵3 = 矩阵2。然后就是矩阵快速幂了。
1
| 1 | ai | bi | ai*bi | Si |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |
2
| 1 | ai+1 | bi+1 | ai+1*bi+1 | Si+1 |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 |
3
| 1 | AY | BY | AY*BY | AY*BY |
| 0 | AX | 0 | AX*BY | AX*BY |
| 0 | 0 | BX | AY*BX | AY*BX |
| 0 | 0 | 0 | AX*BX | AX*BX |
| 0 | 0 | 0 | 0 | 1 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
#define LL __int64
#define MOD 1000000007
typedef struct
{
LL m[][];
}mat;
mat X, Y;
LL n, a0, ax, ay, b0, bx, by;
mat multi(mat a, mat b)
{
mat c; int j, i, k;
; i < ; ++i)
{
; j < ; ++j)
{
c.m[i][j] = ;
; k < ; ++k)
{
c.m[i][j] += a.m[i][k] * b.m[k][j]%MOD;
}
c.m[i][j] %= MOD;
}
}
return c;
}
mat power(LL k)
{
mat ans = X, p = Y;
while (k)
{
) ans = multi(ans, p);
k /= ; p = multi(p, p);
}
return ans;
}
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin );
#endif // ONLINE_JUDGE
ios::sync_with_stdio(false);
while (cin>>n>>a0>>ax>>ay>>b0>>bx>>by)
{
"<<endl; continue;}
memset(X.m, , sizeof(X.m));
memset(Y.m, , sizeof(Y.m));
X.m[][] = , X.m[][] = a0%MOD, X.m[][] = b0%MOD,
X.m[][] = a0*b0%MOD, X.m[][] = a0*b0%MOD;
Y.m[][] = , Y.m[][] = ay%MOD, Y.m[][] = by%MOD,
Y.m[][] = ay*by%MOD, Y.m[][] = ay*by%MOD, Y.m[][] = ax%MOD,
Y.m[][] = ax*by%MOD, Y.m[][] = ax*by%MOD, Y.m[][] = bx%MOD,
Y.m[][] = ay*bx%MOD, Y.m[][] = ay*bx%MOD, Y.m[][] = ax*bx%MOD,
Y.m[][] = ax*bx%MOD, Y.m[][] = ;
mat ans = power(n-);
LL touch = ans.m[][];
cout << touch <<endl;
}
;
}
注意 n==0 的时候特判呐~
走吧,小胖!
hdu4686 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 因为ai = ai-1*AX+AY ,bi = bi-1*BX+BY ,那么ai*bi=AX*B ...
- HDU 5667 构造矩阵快速幂
HDU 5667 构造矩阵快速幂 题目描述 解析 我们根据递推公式 设 则可得到Q的指数关系式 求Q构造矩阵 同时有公式 其中φ为欧拉函数,且当p为质数时有 代码 #include <cstdi ...
- hdu 4565 So Easy! (共轭构造+矩阵快速幂)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4565 题目大意: 给出a,b,n,m,求出的值, 解题思路: 因为题目中出现了开根号,和向上取整后求 ...
- HUST 1569(Burnside定理+容斥+数位dp+矩阵快速幂)
传送门:Gift 题意:由n(n<=1e9)个珍珠构成的项链,珍珠包含幸运数字(有且仅由4或7组成),取区间[L,R]内的数字,相邻的数字不能相同,且旋转得到的相同的数列为一种,为最终能构成多少 ...
- hdu 1757 (矩阵快速幂) 一个简单的问题 一个简单的开始
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757 题意不难理解,当x小于10的时候,数列f(x)=x,当x大于等于10的时候f(x) = a0 * ...
- D. Magic Gems(矩阵快速幂 || 无敌杜教)
https://codeforces.com/contest/1117/problem/D 题解:有一些魔法宝石,魔法宝石可以分成m个普通宝石,每个宝石(包括魔法宝石)占用1个空间,让你求占用n个空间 ...
- HDU4686 Arc of Dream 矩阵快速幂
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
随机推荐
- (二)Kafka动态增加Topic的副本(Replication)
(二)Kafka动态增加Topic的副本(Replication) 1. 查看topic的原来的副本分布 [hadoop@sdf-nimbus-perf ~]$ le-kafka-topics.sh ...
- 文档批量格式化之word技能
一.在条目末尾添加# Ctrl + H 然后将 ^p替换为#^p 二.繁体字转换为简体字 在word 审阅-->简转繁(繁转简)都可以相互互转 三.将表格的变成字典或者规则的字符串格式 结合Ex ...
- 协同过滤 CF & ALS 及在Spark上的实现
使用Spark进行ALS编程的例子可以看:http://www.cnblogs.com/charlesblc/p/6165201.html ALS:alternating least squares ...
- C++ 不能在类体外指定关键字static
C++ static 函数的问题 近日读 C++ primer 中static 一章 , 有这么一句话, “静态成员函数的声明除了在类体中的函数声明前加上关键字static 以及不能声明为const ...
- 【转】 深入main函数中的参数argc,argv的使用详解
C/C++语言中的main函数,经常带有参数argc,argv,如下: 复制代码 代码如下: int main(int argc, char** argv) 这两个参数的作用是什么呢?argc 是指命 ...
- android 破解工具
来记录一下本人在平时工作中使用的android上的破解工具 静态破解: apktool: apk包 -> dex dex2jar和enjarify(google官方出品): dex->ja ...
- Rotate Image [LeetCode]
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- C# 字符串转义和反转义
System.Text.RegularExpressions.Regex.Unescape(s) System.Text.RegularExpressions.Regex.Escape(s)
- 51nod 1264 线段相交(几何)
题目链接:51nod 1264 线段相交 如果两条线段相交,则需满足一条线段的一个端点在另一条线段上,或者 两条线段都分别跨越另一条线段延伸的直线上.(如果点p1位于直线p3p4的一边,而点p2位于该 ...
- Linux共享对象之编译参数fPIC
最近在看Linux编程的基础知识,打算对一些比较有趣的知识做一些汇总备忘,本文围绕fPIC展开,学习参考见文末. 在Linux系统中,动态链接文件称为动态共享对象(DSO,Dynamic Shared ...