题目链接  Broken Clock   中文题面链接

令$cos(xα) = f(x)$

根据三角函数变换公式有

$f(x) = \frac{2d}{l} f(x-1) - f(x-2)$

我们现在要求的是$l * f(t)$,把$f(t)$表示成$\frac{p}{q}$的形式

令$f(x) = \frac{g(x)}{l^{x}}$,那么$g(x) = p, l^{x} = q$

$\frac{g(x)}{l^{x}} = \frac{2d}{l} * \frac{g(x-1)}{l^{x-1}} - \frac{g(x-2)}{l^{x-2}}$

$g(x) = 2dg(x-1) - l^{2}g(x-2)$

那么这就是一个很显然的矩阵加速的套路,用矩阵快速幂求解$g(t)$即可。

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; const LL mod = 1e9 + 7; struct Matrix{ LL arr[3][3]; } unit, a, c; LL p, q, d, l, t;
int T, n; inline LL Pow(LL a, LL b, LL mod){
LL ret(1);
for (; b; b >>= 1, (a *= a) %= mod) if (b & 1) (ret *= a) %= mod;
return ret;
} Matrix Mul(Matrix a, Matrix b){
Matrix c;
rep(i, 1, n) rep(j, 1, n){
c.arr[i][j] = 0;
rep(k, 1, n) (c.arr[i][j] += (a.arr[i][k] * b.arr[k][j] % mod)) %= mod;
}
return c;
} Matrix Pow(Matrix a, int k){
Matrix ret(unit); for (; k; k >>= 1, a = Mul(a, a)) if (k & 1) ret = Mul(ret, a); return ret;
} int main(){ n = 2;
unit.arr[1][1] = unit.arr[2][2] = 1; scanf("%d", &T);
while (T--){
scanf("%lld%lld%lld", &l, &d, &t);
q = Pow(l, t, mod);
c.arr[1][1] = 2 * d % mod;
c.arr[1][2] = -l * l % mod;
c.arr[1][2] += mod;
c.arr[1][2] %= mod;
c.arr[2][1] = 1;
c.arr[2][2] = 0;
--t;
a = unit;
while (t){
if (t & 1) a = Mul(a, c);
t >>= 1;
c = Mul(c, c);
} p = (a.arr[1][1] * d % mod + a.arr[1][2] % mod) % mod;
p %= mod;
printf("%lld\n", l * p % mod * Pow(q, mod - 2, mod) % mod);
} return 0;
}

  

CodeChef February Challenge 2018 Broken Clock (三角函数推导 + 矩阵快速幂)的更多相关文章

  1. 2018.09.26 bzoj5221: [Lydsy2017省队十连测]偏题(数学推导+矩阵快速幂)

    传送门 由于没有考虑n<=1的情况T了很久啊. 这题很有意思啊. 考试的时候根本不会,骗了30分走人. 实际上变一个形就可以了. 推导过程有点繁杂. 直接粘题解上的请谅解. 不得不说这个推导很妙 ...

  2. [ An Ac a Day ^_^ ] hdu 4565 数学推导+矩阵快速幂

    从今天开始就有各站网络赛了 今天是ccpc全国赛的网络赛 希望一切顺利 可以去一次吉大 希望还能去一次大连 题意: 很明确是让你求Sn=[a+sqrt(b)^n]%m 思路: 一开始以为是水题 暴力了 ...

  3. codechef February Challenge 2018 简要题解

    比赛链接:https://www.codechef.com/FEB18,题面和提交记录是公开的,这里就不再贴了 Chef And His Characters 模拟题 Chef And The Pat ...

  4. CodeChef February Challenge 2018 Points Inside A Polygon (鸽笼原理)

    题目链接  Points Inside A Polygon 题意  给定一个$n$个点的凸多边形,求出$[ \frac{n}{10}]\ $个凸多边形内的整点. 把$n$个点分成$4$类: 横坐标奇, ...

  5. HDU6030 Happy Necklace(推导+矩阵快速幂)

    HDU6030 Happy Necklace 推导或者可以找规律有公式:\(f[n] = f[n-1] + f[n-3]\) . 构造矩阵乘法: \[ \begin{pmatrix} f_i \\ f ...

  6. LightOJ 1070 - Algebraic Problem 推导+矩阵快速幂

    http://www.lightoj.com/volume_showproblem.php?problem=1070 思路:\({(a+b)}^n =(a+b){(a+b)}^{n-1} \) \(( ...

  7. CodeChef-----February Challenge 2018---Broken Clock(极坐标+三角函数递推+矩阵快速幂)

    链接:  https://www.codechef.com/FEB18/problems/BROCLK Broken Clock Problem Code: BROCLK Chef has a clo ...

  8. Codechef October Challenge 2018 游记

    Codechef October Challenge 2018 游记 CHSERVE - Chef and Serves 题目大意: 乒乓球比赛中,双方每累计得两分就会交换一次发球权. 不过,大厨和小 ...

  9. Codechef September Challenge 2018 游记

    Codechef September Challenge 2018 游记 Magician versus Chef 题目大意: 有一排\(n(n\le10^5)\)个格子,一开始硬币在第\(x\)个格 ...

随机推荐

  1. 踩到Framework7 Photo Browser 的一个坑

    最近在做的项目用了Framework7前端框架,功能确实比较强大!但这两天遇到一个坑,希望我的这点收获能给遇到这个问题的朋友一点帮助. 在使用Photo Browser 的时候,图片下方想放一个“点赞 ...

  2. WIN8、WIN7访问Windows Server 2003服务器的数据库速度很慢、远程速度很慢的解决方法

    原因是微软在WIN7开始上加入了网络速度限制.在控制台执行以下命令即可解决: netsh interface tcp set global autotuninglevel=disabled

  3. IIS相关服务和无法启动服务W3SVC错误提示

    首先,打开“服务”查看下面的服务是否启动.(下面的两个服务就是跟IIS相关的服务,计算机(右键)->管理->服务和应用程序->服务) Windows Process Activati ...

  4. jvm可视化工具jvisualvm插件——Visual GC

    转自:http://blog.csdn.net/xuelinmei_happy/article/details/51090115 Visual GC是一个Java 内存使用分析与GC收集的可视化工具插 ...

  5. time模块与random模块,六位含字母随机验证码

    # time模块# import time# time.time()#计算这一时刻时间戳 *******# time.sleep(1)#让cpu休眠一定时间 *******# time.clock() ...

  6. 分享6个网址二维码API接口

    1.http://pan.baidu.com/share/qrcode?w=150&h=150&url=http://www.54admin.net 2.http://b.bshare ...

  7. 孤荷凌寒自学python第二十七天python的datetime模块及初识datetime.date模块

    孤荷凌寒自学python第二十七天python的datetime模块及初识datetime.date模块 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 一.datetime模块 dateti ...

  8. HDU 3577 Fast Arrangement ( 线段树 成段更新 区间最值 区间最大覆盖次数 )

    线段树成段更新+区间最值. 注意某人的乘车区间是[a, b-1],因为他在b站就下车了. #include <cstdio> #include <cstring> #inclu ...

  9. 【bzoj3638】Cf172 k-Maximum Subsequence Sum 模拟费用流+线段树区间合并

    题目描述 给一列数,要求支持操作: 1.修改某个数的值 2.读入l,r,k,询问在[l,r]内选不相交的不超过k个子段,最大的和是多少. 输入 The first line contains inte ...

  10. Arcgis桌面开发,Python引用GDAL库的方法

    我用的是arcgis10.2,python版本是arcgis自动安装的Pythin2.7 1.下载gdal-111-1700-core.msi和对应的GDAL-1.11.1.win32-py2.7.m ...