数学 (OI)

news/2025/2/3 16:47:44/文章来源:https://www.cnblogs.com/hangry/p/18697560

数学 (OI)

前言

说实话这首歌有点反。

Jay of Love
Another sunrise, another sunset
Soon it'll all be yesterday
Another good day, another bad day,
What did you do today?
Why do we choose to chase what we'll lose?
What you want isn't what you have.
What you have may not be yours, to keep.
If I could find love, at a stop, in a park with open arms,
I would save all my love, in a jar,
made of sparks, sealed in my beating heart,
Could it be yours to keep, the Jar of Love.
Another left turn, another head turns
Could he be someone I deserve?
Another right turn, another lesson learned
Never leave an open flame to burn
Why do we choose to chase what we'll lose?
What you want isn't what you have.
What you have may not be yours, to keep.
If I could find love,
at a stop, in a park with open arms,
I would save all my love,
in a jar,made of sparks,
sealed in my beating heart,
Could it be yours to keep, the Jar of Love.
Could you be my love
Could you be my love
Could you be my love
Could you be my love
Could you be her love
Could you be his love
Could you be my love
Could I be you love
If I could find love,
at a stop, in a park with open arms,
I would save all my love,
in a jar,made of sparks,
sealed in my beating heart,
Could it be yours to keep
If I could find love,
at a stop, in a park with open arms,
I would save all my love,
in a jar,made of sparks,
sealed in my beating heart,
Could it be yours to keep
If I could find love,
at a stop, in a park with open arms,
I would save all my love,
in a jar,made of sparks,
sealed in my beating heart,
Could it be yours to keep
the Jar of Love.
Could it be yours to keep
the Jar of Love.
Could it be yours to keep
the Jar of Love.

可能是最后一篇学习笔记。

FFT 学习笔记

傅里叶

很久之前就学了,现在好像忘了,连着 ntt,fwt 重新学一下。顺便打个学习笔记。

\(n\) 当做 \(2^k\)

用复数做多项式的根,具体的,\(x = w^1_n\) 一次单位根, 即 \((\cos \frac{2 \pi}{n}, \sin \frac{2 \pi}{n})\)

理由的话可以证一下:

\(A(x) = \sum\limits_{i = 0}^{n - 1}a_ix^i\) 多项式,\(x\)\(0 \dots n - 1\) 次单位根带出来的离散傅里叶变换为 \((y_0, \dots, y_{n - 1})\), 接着设 \(B(x) = \sum\limits_{i = 0}^{n - 1}y_ix^i\), 将 \(x^{-1}\) 带入作单位根得出新的离散傅里叶变换 \((z_0, \dots, z_{n - 1})\)

那按题意模拟,

\[\begin{aligned}z_k &= \sum_{i = 0}^{n - 1}y_i \left(\omega_{n}^{k}\right)^{-i} \\&= \sum_{i = 0}^{n - 1}\left(\sum_{j = 0}^{n - 1}a_j \left(\omega_{n}^{j}\right)^j\right) \left(\omega_{n}^{k}\right)^{-i} \\&= \sum_{j = 0}^{n - 1} a_j\left(\sum_{i = 0}^{n - 1}(\omega_{n}^{j - k})^i\right) \\&= na_k \end{aligned}\]

所以这个玩意儿就是做两遍傅里叶变换的事儿。

快速

然后就是优化复杂度的问题了。傅里叶叔叔作为一个连电脑都没见过的人,他是闲得蛋疼才会优化复杂度,于是他蛋完好。

后人用分治优化了 fft 复杂度。

具体原理如下:

\(A(x) = a_0x^0 + \dotsb + a_{n - 1}x^{n - 1}\), 按奇偶分个类:

\[A(x) = (a_0 + a_2x^2 + \dotsb + a_{n - 2}x^{n - 2}) + (a_1x + \dotsb + a_{n - 1}x^{n - 1}) \]

整俩多项式:

\[A_1(x) = a_0 + a_2x + \dotsb + a_{n - 2}x^{\frac{n}{2} - 1} \]

\[A_2(x) = a_1 + a_3x + \dotsb + a_{n - 1}x^{\frac{n}{2} - 1} \]

显显显 \(A(x) = A_1(x^2) + xA_2(x^2)\)

假设 \(k < \frac{n}{2}\),将 \(x = \omega_{n}^{k}\) 带入,

\[\begin{aligned} A(\omega_{n}^k) &= A_1(\omega_n^{2k}) + \omega_n^kA_2(\omega_n^{2k}) \\ &= A_1(\omega_{\frac{n}{2}}^{k}) + \omega_n^kA_2(\omega_{\frac{n}{2}}^{k}) \end{aligned} \]

对于 \(A(\omega_{n}^{k + \frac{n}{2}})\)

\[\begin{aligned} A(\omega_{n}^{k + \frac{n}{2}}) &= A_1(\omega_n^{2k + n}) + \omega_n^{k + \frac{n}{2}}A_2(\omega_n^{2k + n}) \\ &= A_1(\omega_{\frac{n}{2}}^{k}) - \omega_n^kA_2(\omega_{\frac{n}{2}}^{k}) \end{aligned}\]

所以只要对于 \(A_1A_2\)\((\omega_{\frac{n}{2}}^{0} \dotsb \omega_{\frac{n}{2}}^{\frac{n}{2} - 1})\) 就可以求出 \(A\)\((\omega_{n}^{0} \dotsb \omega_{n}^{n - 1})\) 离散傅里叶变换。

\(n - 1\) 直接 return

实现

其实还有递归版,就是常数忒他妈大,写了也没啥意义,就不写了,这里是倍增法,比较快。

然后就是各位 大牛 们纷纷拽高级名词,什么蝴蝶变换,根本看不懂。

然后看代码就是用个变量数组存起来,减少常数。

\(QwQ\), 有点唐。

考虑一下非递归实现就是要从下往上走,那么我们就需要最终位置。

简单手摸一下得出, \(x\) 的最后位置是其二进制翻转的值。

一点一点向上还原即可。

CODE
#include <bits/stdc++.h>
typedef long long ll; 
using namespace std; 
const int N = (1 << 21) + 100; 
class _complex {
private:
double x, y; 
public:
_complex(double X = 0, double Y = 0): x(X), y(Y) {}
inline double Real() {return x; }
inline double Imag() {return y; }
inline _complex operator + (_complex a) {return _complex(x + a.x, y + a.y); }
inline _complex operator - (_complex a) {return _complex(x - a.x, y - a.y); }
inline _complex operator * (_complex a) {return _complex(x * a.x - y * a.y, a.x * y + x * a.y); }
} a[N], b[N]; 
int n, m, num = 1; 
const double Pi = acos(-1.0); 
int l, r[N]; void FFT(_complex *A, int type) {for (int i = 0; i < num; ++ i) {if (i < r[i]) swap(A[i], A[r[i]]); }for (int mid = 1; mid < num; mid <<= 1) {_complex Wn = _complex(cos(Pi / mid), sin(Pi / mid) * type); for (int R = mid << 1, j = 0; j < num; j += R) {_complex w = _complex(1, 0); for (int k = 0; k < mid; ++ k, w = w * Wn) {_complex x = A[j + k], y = w * A[j + k + mid]; A[j + k] = x + y, A[j + mid + k] = x - y; }}}
}signed main() {freopen("1.in", "r", stdin); freopen("1.out", "w", stdout); ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m; for (int i = 0, x; i <= n; ++ i) cin >> x, a[i] = _complex(x, 0); for (int i = 0, x; i <= m; ++ i) cin >> x, b[i] = _complex(x, 0); while (num <= n + m) num <<= 1, ++ l; for (int i = 0; i < num; ++ i) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1)); FFT(a, 1), FFT(b, 1); for (int i = 0; i < num; ++ i) a[i] = a[i] * b[i]; FFT(a, -1); for (int i = 0; i <= n + m; ++ i) cout << (int)(a[i].Real() / num + 0.5) << ' '; 
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/878303.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【每日一题】20250203

你是万千星球的星球! 你是沸腾的准则!你是精心保存的潜伏的萌芽!你是核心!【每日一题】我国发射的“天宫一号”和“神州八号”在对接前,”天宫一号”的运行轨道高度为 \(350 \; \mathrm{km}\),“神州八号”的运行轨道高度为 \(343 \; \mathrm{km}\).它们的运行轨道均视为…

题解:P11637 Mod

题解:P11637 Mod 题目传送门 思路 一种比较简单的方法。 根据题意,我们可以发现在若干次操作后 \(a\) 能变成 \(0\) 的情况下,操作次数为 \(p-a\)。因为 \(b\) 的操作次数与 \(a\) 相同,所以 \(b\) 的值为 \(b-(p-a)\)。因为题面中要求 \(b\) 为一个自然数,所以自然就分成…

如何在markdown中写出横线除号

在 Markdown 中,您可以使用支持 LaTeX 数学公式的环境来表示“除数在上面,被除数在下面”的数学公式形式。以下是具体方法: 1. 使用分数形式 用 LaTeX 的 \frac 表达分数(除号的形式): 块级公式: $$\frac{a}{b}$$内联公式: $\frac{a}{b}$2. 使用纯文本的替代表示法 如果…

彻底搞懂分布式事务 XA 模式

原文地址: https://developer.aliyun.com/article/783796 简介: XA 协议是由 X/Open 组织提出的分布式事务处理规范,主要定义了事务管理器 TM 和局部资源管理器 RM 之间的接口。目前主流的数据库,比如 oracle、DB2 都是支持 XA 协议的。作者 | 朱晋君来源 | 阿里巴巴云原生…

.net6-jwt实现认证和自定义策略授权

场景 客户端根据用户名和密码访问登录接口获取token,服务端登录接口获取账号和密码进行验证,获取用户的角色,若角色是超级管理员则只能授权访问标记为超级管理员的接口,若角色是管理员则只能授权访问标记为管理员的接口。 实现JWT认证 安装JWT包 Microsoft.AspNetCore.Auth…

「ZJOI2017」树状数组 题解

前言 题目链接:洛谷;UOJ;LOJ。 UOJ 上有很强的数据。 题意简述 yzh 做 OI 题维护序列 \(\{a_n\}\)。 她实现了一个后缀和查询函数 \(\displaystyle f(x) = \begin{cases} 0 & \text{ if } x=0 \\ \sum\limits_{i=x}^n a_i & \text{ otherwise } \end{cases}\),和…

什么是SDK?

1. 什么是SDK?1.1. SDK的定义 1.2. SDK的组成 1.3. 举例说明1.3.1. 【示例一】 OpenCV 1.3.2. 【示例二】 JDK 1.3.3. 【示例三】微信SDK2. SDK与API2.1. 什么是API? 2.2. SDK与API的关系3. 什么是SDK开发?3.1. SDK开发包含哪些过程? 3.2. SDK开发的目标是什么? 3.3. SDK开…

小蚁摄像头通过rclone+alist实现监控视频自动上传至云盘

最近,我才发现我白嫖的一刻相册空间才到5g于是就想着把监控录制的视频全传到里面可是,这么搞好像有点麻烦,能不能让我的摄像头自己上传呢? 我的摄像头的型号是小蚁 1080p,刷入了yi-hack-v5 alist 开启ftp yi-hack-v5 ftp界面结果发现不行,放弃了 又看到这位老哥的samba方…

材料检测取样手册系统

为方便查询,特写了查询系统,支持桌面版和网页版,支持Excel导入数据库,支持数据库导出Excel,支持数据库备份,支持恢复数据库。数据库为MySQL

《操作系统真象还原》第十二章 进一步完善内核

本文是对《操作系统真象还原》第十二章学习的笔记,欢迎大家一起交流,目前所有代码已托管至 fdx-xdf/MyTinyOS 。第十二章 进一步完善内核 本文是对《操作系统真象还原》第十二章学习的笔记,欢迎大家一起交流,目前所有代码已托管至 fdx-xdf/MyTinyOS 。 实现系统调用 getpid…

深度学习(RNN,LSTM,GRU)

三个网络的架构图: RNN:LSTM:GRU:特性对比列表:特性RNNLSTMGRU门控数量无3门(输入/遗忘/输出)2门(更新/重置)记忆机制 仅隐藏状态ht显式状态Ct + 隐藏状态ht隐式记忆(通过门控更新状态)核心操作 直接状态传递门控细胞状态更新 门控候选状态混合 计算复杂度O(d2)(1组权…