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 ...
随机推荐
- C#定时执行一个操作
一个客户端向服务器端socket发送报文,但是服务器端限制了发送频率,假如10秒内只能发送1次,这时客户端也要相应的做限制,初步的想法是在配置文件中保存上次最后发送的时间,当前发送时和这个上次最后时间 ...
- MySQL 5.6 双机热备
目录: 1.说明 2.数据手工同步 3.修改主数据库配置文件 4.修改从数据库配置文件 5.主数据库添加备份用户 6.从数据库设置为Slave 7.验证 1.说明 1)数据库版本要高于5.1 2) ...
- touch穿透
出现穿透的前提:上层绑定touch事件,下层绑定click事件. 解决方案:touchend绑定: e.preventDefault();$(下层).css("pointer-events& ...
- createjs 的 bitmapdata类
今天测试一个功能,在效率上出现了问题.2D舞台绘制了大量的元素,联想到AS3的 bitmapdata.darw() 功能,遗憾是createjs官方类 中没有bitmapdata类. 好在已经有大神替 ...
- 利用gitHub搭建博客
##1.gitHub Page的的使用我觉得这边博文写的很清楚,方法.步骤.优缺点以及实例,所以就借用一下啦^_^ [搭建一个免费的,无限流量的Blog](http://www.ruanyifeng. ...
- HDU-4532 湫秋系列故事——安排座位 组合数学DP
题意:有来自n个专业的学生,每个专业分别有ai个同学,现在要将这些学生排成一行,使得相邻的两个学生来自不同的专业,问有多少种不同的安排方案. 分析:首先将所有专业的学生视作一样的,最后再乘以各自学生的 ...
- Java通过jedis操作redis缓存
package com.wodexiangce.util; import java.util.Set; import redis.clients.jedis.Jedis; /** * redis工具类 ...
- dubbo配置文件xml校验报错
配置dubbo服务xml后,程序能正常执行,但validate会出现一些异常: Multiple annotations found at this line: - cvc-complex-type. ...
- laravel Ajax post方式的使用
以jquery ajax 的post的方式为例 验证邮箱输入格式是否正确 html <div class="fl"> <input type="emai ...
- jq知识总结
jQuery jQuery基本选择器: id选择器 $("#div1") class选择器 $(".div1") 元素选择器 $(" ...