
数学
exmy
Less is more, and more is less.
展开
-
数论--中国剩余定理
中国剩余定理(Chinese Remainder Theorem: CRT):求解一次同余式组。 给出以下一元线性同余方程组: (S):⎧⎩⎨x≡a1(mod m1)x≡a2(mod m2)x≡a3(mod m3)(S): \begin{cases}x \equiv a_1 (mod \text{ } m_1) \\x \equiv a_2 (mod \text{ } m_2) \\x原创 2016-04-14 14:29:25 · 621 阅读 · 0 评论 -
codeforces--650A Watchmen(math)
CF 650A题意求 |xi−xj|+|yi−yj|=(xi−xj)2+(yi−yj)2−−−−−−−−−−−−−−−−−√|x_i - x_j| + |y_i - y_j| = \sqrt{(x_i - x_j)^2 + (y_i - y_j)^2} 的个数。题解显然,只有xi==xjx_i == x_j 或者 yi==yjy_i == y_j 的时候才相等。#include <bits/stdc原创 2016-03-14 19:04:15 · 487 阅读 · 0 评论 -
UVa--11181 Probability|Given(math)
UVa 11181题意n个人去超市逛,其中第ii个人买东西的概率为PiP_i,已知有rr个人买了东西,计算每个人实际买了东西的概率。 1<=n<=201 <= n <= 20, 0<=r<=n0 <= r <= n题解实际上这是计算条件概率:P(Ei|E)=P(EiE)P(E)P(E_i | E) = \frac{P(E_i E)}{P(E)} 其中 P(Ei)P(E_i)表示第ii个人买东西的原创 2016-02-19 22:14:19 · 414 阅读 · 0 评论 -
UVa--10491 Cows and Cars(math)
UVa 10491题解设 a = NCOWS, b = NCARS, c = NSHOW 选择某扇门后,主持人再打开 c 个牛门,这时还剩下 a + b - c - 1 扇门未开,也只有这些门是可换的。 假设一开始选择了牛门:最后选到车的概率为, aa+b∗ba+b−c−1\frac{a}{a + b} * \frac{b}{a + b - c - 1} 假设一开始选择了车门:最后选到车的概率原创 2016-02-19 15:23:13 · 442 阅读 · 0 评论 -
UVa--1636 Headshot(概率)
UVa 1636题意你和人决斗。决斗规则如下:用一把有n个弹槽的左轮手枪,对着自己脑袋来一枪,孰生孰死看天意。现在对方已经装了若干发子弹,并随机转了一下转轮,子弹呢用一个01序列表示,0表示这个弹槽无子弹,1表示有子弹。对方先对着自个脑袋开了一枪,嗯,你只听到了一声’click’,人还好好的,是空枪。现在轮到你了,摆在你面前的有两个选择,一是直接对自己开射,二是转一下转轮再来开射,显然你会选择生还希原创 2016-02-19 14:27:47 · 1068 阅读 · 0 评论 -
UVa--12716 GCD XOR(math)
UVa 12716题意给定整数n,求有多少对整数(a, b)满足: 1 <= b <= a <= n,且 gcd(a, b) = x ^ b.题解设 c=gcd(a,b)=a Xor bc = gcd(a, b) = a \text{ Xor } b, 则: c 是 a 的约数,b=a Xor cb = a \text{ Xor } c 因此,可以枚举 a 和 c,为降低枚举的复杂度,利用 c原创 2016-02-18 23:07:35 · 419 阅读 · 0 评论 -
UVa--10791 Minimum Sum LCM(math)
UVa 10791题解算术基本定理的应用。 将n分解,n=pa11pa22...pakkn = p_1^{a_1}p_2^{a_2} ... p_k^{a_k},可知将每个pakkp_k^{a_k}作为一个因子时最优。 注意当 n = 1和 n 为素数的时候,最小和为 n+1n + 1.#include <bits/stdc++.h>using namespace std;int main()原创 2016-02-18 21:11:55 · 367 阅读 · 0 评论 -
UVa--10375 Choose and divide(math)
UVa 10375题解C(p,q)C(r,s)=p!(r−s)!s!q!(p−q)!r!\frac{C(p, q)}{C(r, s)} = \frac{p!(r - s)!s!}{q!(p - q)!r!} 根据算术基本定理:n=pa11pa22...pakkn = p_1^{a_1} p_2^{a_2}...p_k^{a_k},其中pkp_k为素数,ai∈N+a_i \in N_+. n!=1原创 2016-02-18 19:04:12 · 486 阅读 · 0 评论 -
hdoj--1023 Train Problem II (高精度乘除法)
Train Problem IITime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7252 Accepted Submission(s): 3902Problem DescriptionAs we all k原创 2015-12-06 20:41:02 · 704 阅读 · 0 评论 -
nyoj--148 fibonacci数列(二)(矩阵快速幂)
nyoj 148 模板记录之。#include <iostream>#include <fstream>#include <cmath>#include <vector>#include <algorithm>using namespace std;typedef vector<int> vec;typedef vector<vec> mat;const int mod = 1000原创 2016-03-15 12:00:07 · 441 阅读 · 0 评论 -
nyoj--1000 又见斐波那契数列(快速幂+欧拉定理)
nyoj 1000题解F(0)=a,F(1)=bF(0) = a, F(1) = b F(n)=F(n−1)F(n−2)F(n) = F(n - 1)F(n - 2) ⇒F(n)=F(n−2)2F(n−3)\Rightarrow F(n) = F(n - 2)^2F(n-3) ⇒F(n)=F(n−3)3F(n−4)2\Rightarrow F(n) = F(n - 3)^3F(n - 4)^2原创 2016-03-17 20:53:06 · 1261 阅读 · 0 评论 -
hdoj--1402 A * B Problem Plus(FFT)
A * B Problem Plus题解因为整数 n=∑k−1i=0ai∗10in = \sum_{i= 0}^{k - 1} a_i * 10^i, A∗BA * B 可视为两个多项式的乘积,从而应用FFT在O(nlogn)O(nlogn)的时间内求解。#include <iostream>#include <cstring>#include <string>#include <cstdi原创 2016-10-07 23:42:51 · 431 阅读 · 0 评论 -
poj--1306 Combinations(组合数)
poj 1306题意计算组合数 (nm)\begin{pmatrix} n \\ m \end{pmatrix}题解没有取模又需要求精确解,阶乘计算不得,逆元求不得。 根据二项式系数公式: (nm)=(n−1m)+(n−1m−1)\begin{pmatrix} n \\ m \end{pmatrix} = \begin{pmatrix} n - 1 \\ m \end{pmatrix} + \b原创 2016-05-27 23:09:01 · 763 阅读 · 0 评论 -
数论--Lucas Theorem
此定理用来求 (nm) mod p\begin{pmatrix} n \\ m \end{pmatrix} \text{ mod } p. ( p 是素数 ) 适用:大的组合数取模。定理给出: (nm)mod p =(n/pm/p)\begin{pmatrix} n \\ m \end{pmatrix} \text{mod p }= \begin{pmatrix} n/p \\ m/p原创 2016-04-20 18:21:14 · 839 阅读 · 0 评论 -
nyoj--300 Kiki & Little Kiki 2(矩阵快速幂)
nyoj 300题解操作函数:f(i)=f(i)^f((i−1+n)%n)f(i) = f(i) \text{^} f((i - 1 + n) \% n)一共有mm次操作,而mm可以达到10810^8的数量级,所以考虑构造一个矩阵加速运算。 构造矩阵: 以n=4n = 4为例 E=∣∣∣∣∣∣1001110001100011∣∣∣∣∣∣E = \begin{vmatrix} 1 &1& 0 &原创 2016-03-24 20:39:36 · 504 阅读 · 0 评论 -
nyoj--299 Matrix Power Series(矩阵 + 二分)
nyoj 299题解Sk=A+A1+A2+...+AkS_k = A + A^1 + A^2 + ... + A^kif k is even : Sk=(A1+A2+…+Ak/2)+Ak/2(A1+A2+…+Ak/2) =Sk/2+Ak/2Sk/2 =Sk/2(E+Ak/2)S_k = (A^1 + A^2 + … + A^{k/2}) + A^{k/2}(A^1 + A^2 + … + A^{k原创 2016-03-23 11:44:52 · 534 阅读 · 0 评论 -
nyoj--298 点的变换(矩阵)
nyoj 298题解参阅Matrix67大神的十个利用矩阵乘法解决的经典题目#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <algorithm>#include <cmath>using namespace std;const int maxn = 10000 + 10;c原创 2016-03-19 00:20:28 · 507 阅读 · 0 评论 -
zoj--1951 Goldbach's Conjecture(math)
zoj 1951题解验证一百万以内的哥德巴赫猜想。 素数打表,然后枚举。#include <iostream>#include <cstdio>#include <vector>#include <algorithm>using namespace std;const int maxn = 1000000 + 10;bool vis[maxn];vector<int> p;int原创 2016-03-18 23:35:02 · 470 阅读 · 0 评论 -
nyoj--301 递推求值(矩阵快速幂)
nyoj 301题解用矩阵加速运算。 ∣∣∣∣∣f(n)f(n−1)1∣∣∣∣∣=∣∣∣∣b10a00c01∣∣∣∣∣∣∣∣∣f(n−1)f(n−2)1∣∣∣∣∣=∣∣∣∣b10a00c01∣∣∣∣n−2∣∣∣∣∣f(2)f(1)1∣∣∣∣∣\begin{vmatrix} f(n) \\ f(n - 1) \\1 \end{vmatrix} = \begin{vmatrix}b & a & c \原创 2016-03-18 21:06:35 · 484 阅读 · 0 评论 -
PAT--1096. Consecutive Factors
Descriptionmong all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecutive numbers. N原创 2016-11-27 19:41:48 · 320 阅读 · 0 评论