题目链接  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. Activiti入门 -- 环境搭建和核心API简介

    相关文章: <史上最权威的Activiti框架学习指南> <Activiti入门 -- 轻松解读数据库> 本章内容,主要讲解Activiti框架环境的搭建,能够使用Activi ...

  2. selenium IDE录制

    一.        安装 可以用Firefox打开https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/,在这里边找到和当前firef ...

  3. Python——数据类型之list、tuple

    本篇主要内容 •  list初识 •  list元素的访问 •  list内部所有的方法 •  tuple介绍和与list用法的比较 我觉得Python里面用的最多的就是List了,感觉好强大.他能存 ...

  4. Error “can't use subversion command line client : svn” Probably the path to Subversion executable is wrong

    错误提示如图. 大概意思就是SVN路径不对 解决方法如下: 首先下载Subversion 1.8.13(1.8) 下载链接(https://www.visualsvn.com/downloads/) ...

  5. 团队项目-第三次scrum 会议

    时间:10.25 时长:30分钟 地点:线上 工作情况 团队成员 已完成任务 待完成任务 解小锐 根据初步讨论结果编写初步的api文档 编写project和projectGenerator类 陈鑫 采 ...

  6. 二分查找树按照key值划分

    #include <iostream>#include <vector>#include <algorithm>#include <string>#in ...

  7. 历届试题 带分数 全排列模板 JAVA

    标题:带分数 100 可以表示为带分数的形式:100 = 3 + 69258 / 714 还可以表示为:100 = 82 + 3546 / 197 注意特征:带分数中,数字1~9分别出现且只出现一次( ...

  8. GCD 开发详情

    目录 一.简介 二.dispatch Queue - 队列 三.dispatch Groups - 组 四.dispatch Semaphores - 信号量 五.dispatch Barriers ...

  9. Redis Sorted Set

    Redis Sorted Set Redis 有序集合和集合一样也是string类型元素的集合,且不允许重复的成员. 不同的是每个元素都会关联一个double类型的分数.redis正是通过分数来为集合 ...

  10. CentOS Linux上搭建PPPoE服务器及拨号设置

    CentOS Linux上搭建PPPoE服务器及拨号设置 搭建PPPoE,成功了的话,就觉得超级简单,在CentOS Linux更是5步左右就能搞定. 1.安装pppoe,安装完成后,会有pppoe- ...