随笔 - 531
文章 - 0
评论 - 3
阅读 -
10215
随笔分类 - 数学
poj 3090 Visible Lattice Points
摘要:#include<iostream> #include<algorithm> using namespace std; const int M=1e6; int vis[M+4],P[M+4],cnt; int fi[M+4]; void shai(int top){ cnt=0; fi[1]=1;
阅读全文
糖果 Candy uva1639
摘要:有两个盒子各有n (n<=2e5) 个糖,每天随机选一个(概率分别为p,1-p),然后吃一颗糖。直到有一天,没糖了!输入n,p,求此时另一个盒子里糖的个数的数学期望 假设最后某个盒子有 k 颗糖,然后计算概率即可 #include<iostream> #include<cstring> #inclu
阅读全文
Crossing Rivers uva12230
摘要:https://www.luogu.com.cn/problem/UVA12230 期望的线性性质 设初始答案 A,为全走陆地的时间 D,则每次输入时去河的长度 L,加上渡河期望时间 2* L/v #include<iostream> #include<cstring> #include<algor
阅读全文
比赛名次 Race uva12034
摘要:两人赛马,最终名次有3种可能 求n人赛马时最终名次的可能性的个数 #include<iostream> #include<cstring> #include<algorithm> #include<set> using namespace std; #define mod 10056 int c[1
阅读全文
纸牌游戏 Double Patience
摘要:记忆化搜索 #include <iostream> #include <cstring> #include <iomanip> using namespace std; double f[5][5][5][5][5][5][5][5][5]; bool v[5][5][5][5][5][5][5][
阅读全文
Headshot UVA - 1636
摘要:#include<iostream> #include<vector> #include<cstring> #include<algorithm> using namespace std; const int N=104; string s; void sov(){ int i; int len=s
阅读全文
GCD等于XOR GCD XOR uva12716
摘要:给定一个数字n,如样例所示格式输出满足1<=b<=a<=n且gcd(a,b)==a xor b的(a,b)二元组个数 #include<iostream> #include<vector> #include<cmath> #include<algorithm> using namespace std
阅读全文
Choose and divide uva 10375
摘要:求C(i,j)/ C(u,v) 公式化简 筛出所有质数 除法的时候: 因数分解, 求对每个质数的个数的贡献 #include <iostream> #include <cstring> #include <cmath> #include <iomanip> #include <vector> usi
阅读全文
A/B mod
摘要:对分数取模,对B求逆元 (费马小定理实现) #define int long long const int mod =1e9+7; int ksm(int x,int y){ if(y==0) return 1; int t= ksm(x,y/2) ; if(y&1) return ((t*t%mo
阅读全文
Counting Arrays CF893E
摘要:给出x和y,求一个长度为y的序列,其乘积为x,允许有负数,求这种序列的个数, x分解质因数,考虑每个 p^e, 把e分为y 份( 可以为0),个数为 C( e+y-1,e) 这题需要乘法逆元 来进行乘法 比如想组合数 n!/ (n-m)! * m! , 转化为 n!* fnv(n-m)! *fnv(
阅读全文
P5664 [CSP-S2019] Emiya 家今天的饭
摘要:给出一个矩阵,要求每行只能选一个节点,每列选的节点不能超过所有选的节点的一半,给出每个节点的选择方案数(a[i][j] ) 不能完全不选,求总方案数 直接容斥,ALL - 存在一个列的所选个数超过一半 但是发现这种列只能存在一个(脑补 枚举这个列, 对这个列做dp : F [ i] [j ][ k
阅读全文
Jzzhu and Sequences CF450B
摘要:其中 f(1)=x0,f(2)=y0, f( i )=f( i-1 )+f( i+1 ),求 f(n) #include <iostream> #include <cmath> #include <algorithm> using namespace std; #define N 2 int mod
阅读全文
Reading comprehension HDU - 4990
摘要:ans=0; for(i=1;i<=n;i++) { if(i&1)ans=(ans*2+1)%m; else ans=ans*2%m; } 使用矩阵快速幂计算 f[n ] f[n] = f[n-1]+f[n-2]*2 +1 { f[n] ,f[n-1] ,1 } = { f[n-1] ,f[ n-
阅读全文
Fibonacci 第 n 项
摘要:#include <iostream> #include <cmath> #include <algorithm> using namespace std; #define N 2 int mod; #define int long long struct matrix { int a[N+2][N
阅读全文
矩阵快速幂
摘要:求矩阵的 k 次幂 #define int long long #define N 3 int mod =1e9+7; struct matrix { int a[N+2][N+2]; }; int n; void init_(matrix &x){ memset(x.a,0,sizeof x.a)
阅读全文
hdu4135
摘要:求 [a,b] 中 与n 互素的数字个数 #include <iostream> #include <algorithm> using namespace std; const int N =200; #define int long long int tot,fac[N]; int hh,q[10
阅读全文
欧拉函数
摘要:对正整数 n,欧拉函数是小于等于 n 的数中与 n 互质的数的个数 性质摘要 1. a,b互质, f(a*b) =f(a)*f(b) 2. f(x^a) = (x-1)* f(x^(a-1)) 3. if i%j==0 f(i*j)= f(i) *j 4. if i%j !=0 f(i*j)=f(i
阅读全文
乘法逆元
摘要:a*b Ξ 1 (mod p) ,则a, b 互为逆元(mod p) 求逆元 1.费马小定理 : p 是一质数, GCD(a,p)==1 , 则 a^(p-1) Ξ 1 (mod p) 由此 a^(p-2) *a Ξ 1 (mod p) , 那么 a^(p-2) 就是a的逆元 2.exgcd #de
阅读全文
线筛与分解质因数
摘要:求出最小质因数,然后做除法 #include <bits/stdc++.h> using namespace std ; const int N=5e3+1; int vis[N],c[N],tot; int g[N]; void init(int top){ vis[1]=1; int i,j;
阅读全文
数学 记录
摘要:http://ybt.ssoier.cn:8088/problem_show.php?pid=1623 http://ybt.ssoier.cn:8088/problem_show.php?pid=1621 http://ybt.ssoier.cn:8088/problem_show.php?pid
阅读全文