自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

嗯。

嗯。

  • 博客(472)
  • 资源 (2)
  • 收藏
  • 关注

原创 HDU 3304 Interesting Yang Yui Triangle lucas定理

输入p n 求杨辉三角的n+1不能被p整除的数有多少个Lucas定理:    A、B是非负整数,p是质数。AB写成p进制:A=a[n]a[n-1]...a[0],B=b[n]b[n-1]...b[0]。    则组合数C(A,B)与C(a[n],b[n])*C(a[n-1],b[n-1])*...*C(a[0],b[0])  mod p同余    即:Lucas(n,m,p)=c(

2014-10-11 13:57:32 1280

原创 Light OJ 1341 Aladdin and the Flying Carpet Pollard_rho整数分解+DFS

输入a b 求有多少对p, q 使得p*q == a && p = b直接大整数分解 然后dfs搜出所有可能的解#include #include #include #include #include using namespace std;typedef long long LL;const int Times = 25;LL factor[100], f[100];i

2014-10-09 15:00:04 1121

原创 Light OJ 1248 - Dice (III) 概率DP

n个面的骰子 求每个面至少扔到一次的期望值设dp[i]为已经扔了i个不同面的期望值 dp[n] = 0 求dp[0]因为dp[i]为还需要扔i个不同的面 每次可能扔中已经扔过的面或者没有扔到过的面2中情况所以dp[i] = (i/n)*dp[i] + (n-i)/n*dp[i+1] +1 等号2边都有dp[i] 移项得dp[i] = dp[i+1]+n/(n-i) #inclu

2014-10-09 12:43:01 1631

原创 Light OJ 1317 Throwing Balls into the Baskets 概率DP

n个人 m个篮子 每一轮每个人可以选m个篮子中一个扔球 扔中的概率都是p 求k轮后所有篮子里面球数量的期望值根据全期望公式 进行一轮球数量的期望值为dp[1]*1+dp[2]*2+...+dp[n]*n 记为w其中dp[i]为i个人扔中的概率 dp[i] = C(n, i)*p^i*(1-p)^(n-i) 最终答案为w*k#include #include using names

2014-10-08 21:33:45 1093

转载 卡特兰数

Catalan数的定义: 设表示用下面的方法把凸多边形区域分成三角形区域的方法数:在有n+1条边的凸多边形区域内通过插入在其中不相交的对角线而把它分成三角形区域。定义。则满足递推关系                        这个递推关系的解是:,这里的叫做Catalan数。  那么上面的递推式的正确性我们可以简单描述一下

2014-10-06 22:00:18 850

原创 HDU 1133 Buy the Ticket 卡特兰数

设50元的人为+1 100元的人为-1 满足前任意k个人的和大于等于0 卡特兰数C(n+m, m)-C(n+m, m+1)*n!*m!import java.math.*;import java.util.*;public class Main { /** * @param args */ public static void main(Str

2014-10-06 21:55:19 979

原创 POJ 3237 Tree 树链剖分

树链剖分基础题#include #include #include using namespace std;const int maxn = 10010;struct edge{ int v, next;}e[maxn*2];int first[maxn], cnt;int top[maxn], dep[maxn], sz[maxn], f[maxn], son[maxn

2014-10-06 00:34:04 1124

原创 ZOJ 3329 One Person Game 带环的概率DP

每次都和e[0]有关系 通过方程消去环dp[i] = sigma(dp[i+k]*p)+dp[0]*p+1dp[i] = a[i]*dp[0]+b[i]dp[i] = sigma(p*(a[i+k]*dp[0]+b[i+k]))+dp[0]*p+1a[i] = sigma(a[i+k]*p)+pb[i] = sigma(b[i+k]*p)+1#include #inc

2014-10-02 23:28:08 905

原创 SGU 495. Kids and Prizes 期望

n个盒子 m个人轮流选 拿走盒子里的奖品 盒子再放回去 求得到奖品的期望可以求没有被选到的奖品的期望 用n减去就是答案#include #include #include #include using namespace std;int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) {

2014-10-02 13:29:10 990

转载 威尔逊定理

威尔逊定理:,其中p为素数。  题目:给定一个正整数n,求表达式:的值。  分析:分两种情况讨论。 (1)3k+7为素数时,那么由威尔逊定理知道,即 此时有,,所以 (2)3k+7为合数时,那么3k+7可以写成:,那么很明显a和b在(3k+6)!中都会出现, 所以,此时

2014-10-01 22:57:15 861

原创 Light OJ 1318 Strange Game 组合数+快速幂+分解因子

长度为l的用k种字符组成的字符串有k^l中 其中m个字符要不相同 那就是k^l*C(l, m)*(k-1)^m 有重复 要除以2 但是你mod n了 不能直接除 n不一定是素数 所以不能乘以逆元所以我都mod 2倍的n 最后的结果再除以2 特判l = 1 和 m = 0的情况#include #include #include using namespace std;typedef

2014-10-01 21:55:39 1469

原创 ZOJ 3557 How Many Sets II lucas 定理

插空法 大组合数取余#include #include using namespace std;typedef long long LL;//求整数x和y,使得ax+by=d, 且|x|+|y|最小。其中d=gcd(a,b) void gcd(LL a, LL b, LL& d, LL& x, LL& y){ if(!b) { d = a; x = 1; y =

2014-09-29 17:13:10 1081

原创 HDU 3966 Aragorn's Story 树链剖分

入门题#include #include #include using namespace std;const int maxn = 50010;struct edge{ int v, next;}e[maxn*2];int n, m, q;int first[maxn], cnt;int top[maxn], tid[maxn], rank[maxn], sz[ma

2014-09-29 16:11:49 1003 2

原创 HDU 3037 Saving Beans 大组合数 lucas定理

直接lucas降到10w以内搞组合数#include #include typedef __int64 LL;LL f[110010];LL pow(LL a, LL b, LL c){ LL ans = 1; while(b) { if(b&1) ans = (ans*a) % c; b >>= 1; a = (a*a) % c; } return an

2014-09-28 19:41:36 880

原创 HDU 3625 Examining the Rooms 第一类斯特林数

最多可以暴力打开k次 对于一个环暴力一次 n个数排成i个(i#include #include using namespace std;typedef __int64 LL;LL dp[22][22];LL f[22];int main(){ dp[0][0] = 1; f[0] = 1; for(int i = 1; i <= 20; i++) { dp[i][i]

2014-09-28 14:53:44 935

原创 Light OJ 1236 Race 第二类斯特林数

第二类斯特林数 n 匹马 分成1 2 3... n组 每一组就是相同排名 没有先后 然后组与组之间是有顺序的 在乘以组数的阶乘#include #include using namespace std;int dp[1010][1010];int a[1010];int main(){ a[0] = 1; dp[0][0] = 1; for(int i = 1; i <= 1

2014-09-27 22:38:30 1567

原创 SGU 108. Self-numbers 2 离线+位优化

可以像筛选法那样标记 但是内存最多只能开1024的int数组 我用了位优化 用一个int 32 位标记32个数字 接下来就离线 排个序 算出第k大的哪个数#include #include #include using namespace std;int a[10000000/32];struct node{ int x, y, id;}b[50010];int get(

2014-09-26 13:49:20 988

原创 SGU 106. The equation 扩展欧几里德

求解的个数对应ax+by=c 根据裴蜀定理c%gcd(a, b) == 0有解 假设d = gcd(a, b)用扩展欧几里德求出方程aax+bb*y=cc 的解x0 y0那么原方程的一个解就是x0*c/d和y0*c/d通解为 x = x0+i*b/dy = y0+i*a/d分别讲x1 x2 带入得到i 满足最小的左区间 y1 y2一样#include #inclu

2014-09-24 20:31:32 989

原创 SGU 103. Traffic Lights 带限制最短路

每个点有2中颜色 只有一条路上的两个点颜色一样才能通过这条路 最短路加上等待的时间处理 处理的是参考别人的 唉还是太弱了#include #include #include #include #include using namespace std;int s, e;int n, m;int a[333];int b[333];int c[333];int first[

2014-09-23 23:51:25 1038

原创 二维线段树模版

HDU 4819 二维线段树模版题#include #include #include using namespace std;const int INF = 999999999;const int maxn = 810;int a[maxn][maxn];int st_min[maxn<<2][maxn<<2];int st_max[maxn<<2][maxn<<2];in

2014-09-22 19:55:47 1602

原创 SGU 101. Domino 欧拉回路

无向图欧拉回路 欧拉通路#include #include using namespace std;struct edge{ int v, next, b, id;}e[210];int vis[210];int first[10], cnt;int ans[210], len;int f[10];int find(int x){ if(x != f[x])

2014-09-22 10:08:18 930

原创 SGU 199. Beautiful People 二维LIS

第一维排序 第二维LIS#include #include #include using namespace std;int dp[100010];int p[100010];struct node{ int x, y, id;}a[100010];bool cmp(node a, node b){ if(a.x != b.x) return a.x < b

2014-09-21 22:58:22 1392

原创 求原根模版

#include #include using namespace std;typedef long long LL;int p[100000], c;LL pow_mod(LL a, LL x, LL m){ LL ans = 1; while(x) { if(x&1) ans = ans * a % m; a = a * a % m; x >>= 1;

2014-09-20 21:37:18 2031

原创 URAL 1268. Little Chu 求最大原根

题目来源:URAL 1268. Little Chu题意:输入n 求一个最大的k 使得k^1 k^2 k^3...k^x mod n 后各不相同思路:mod n 后各不相同 最多有 n个 那么此事k就是原根 因为k #include #include using namespace std;typedef long long LL;int p[100000], c;LL

2014-09-20 21:36:40 1156

原创 HDU 2894 DeBruijin 兹鼓欧拉回路

题目来源:HDU 2894 DeBruijin题意:思路:#include #include using namespace std;int vis[5000], ans[5000];int len, n;void dfs(int u){ int v = ((u<<1)&((1<<n)-1)); if(!vis[v]) { vis[v] = 1; df

2014-09-11 16:55:42 1565

原创 欧拉回路模版

#include #include #include using namespace std;const int maxm = 40010;const int maxn = 1010;int first[maxn], cnt;struct edge{ int u, v, next;}e[maxn*maxn];int ans[maxm];bool vis[maxm];int

2014-09-10 22:11:07 1027

原创 splay树模版

#include #include using namespace std;typedef long long LL;const int maxn = 100010;int pre[maxn], ch[maxn][2], sz[maxn];int root, top1;int s[maxn], top2;//内存池 LL sum[maxn];int val[maxn], add

2014-09-03 14:38:04 942

原创 URAL 1439. Battle with You-Know-Who treap树

题目来源:URAL 1439. Battle with You-Know-Who题意:开始有数列1, 2, 3, ... L k输出第k大的数 D k删除第k大的数思路:treap树插入删除的数 每次二分查找第k大的数为mid 查询treap小于等于mid的数有y个 那么mid应该是第mid-y大的数 与k比较 继续二分#include #include #include #in

2014-09-02 14:28:03 1083

原创 HDU 3726 Graph and Queries treap树

题目来源:HDU 3726 Graph and Queries题意:见白书思路:刚学treap 参考白皮书#include #include #include using namespace std;struct Node{ Node *ch[2]; int r; int v; int s; Node(int v): v(v) { ch[0] = ch[1]

2014-09-01 20:50:14 1356

原创 URAL 1141. RSA Attack RSA加密算法

题目来源:URAL 1141. RSA Attack题意:给你e n c 并且有m^e = c(mod n) 求 m思路:首先学习RSA算法 here 过程大致是1.发送的信息是m2.随机选择两个质数 p和q, n = q*p, n的欧拉函数值φ(n)= (p-1)*(q-1)这个需要证明 3.选择一个与φ(n)互质的并且小于φ(n)的数e, 计算c = m^e(mod

2014-08-31 14:55:48 1536 3

原创 URAL 1019. Line Painting 线段树 区间合并 离散化

题目来源:URAL 1019. Line Painting题意:求最长的一段全部为白色的区间思路:线段树成段更新 区间合并 离散化 这里对应的是一段区间 所以每次不是m+1 而是 l m 和 m r 了 另外我加上了0 和 10^9 这两个点 每一段区间(l, r)我记录的是l和r之间有多少条线段 #include #include #include using namesp

2014-08-31 14:24:03 1143

原创 URAL 1204. Idempotents 扩展欧几里德

题目来源:URAL 1204. Idempotents题意:输入n(n = p*q p,q是质数) 并且x*x=x(mod n) 求x思路: x*x=x(mod n)  -> x*x+k*n=x -> x*(x-1)/n = k 所以 0 和 1 是一组解 因为n = p*q 且x*(x-1)%(p*q)== 0 x 1.x有p因子x-1有q因子x%p == 0且(x-1)%q =

2014-08-31 13:57:47 1148

原创 算法及定理证明

RSA算法原理

2014-08-30 20:59:32 1145

原创 Miller_Rabin大素数测试与Pollard_rho整数分解模版

#include #include #include #include using namespace std;typedef __int64 LL;const int Times = 20;LL factor[100], l;LL gcd(LL a, LL b){ return b ? gcd(b, a%b):a;}LL add_mod(LL a, LL b, LL n)

2014-08-30 20:21:15 1105

原创 POJ 2480 Longge's problem 积性函数

题目来源:POJ 2480 Longge's problem题意:求i从1到n的gcd(n, i)的和思路:首先如果m, n 互质 gcd(i, n*m) = gcd(i, n)*gcd(i, m) 这是一个积性函数积性函数的和还是积性函数由欧拉函数知识得 phi(p^a) = p^a - p^(a-1) p是素数 a是正整数得到最终答案f(n) = f(p1^a1

2014-08-30 10:08:40 913

原创 URAL 1732 . Ministry of Truth KMP

题目来源:URAL 1732 . Ministry of Truth题意:把第一个字符串处理一下 变成第二个 不要的字符改成下划线 空格不能改思路:对第二个字符串单词分割 得到每一个单词后从第一个字符串中匹配 匹配成功 记录当前匹配的位置 然后下一个单词从x+2处在匹配 知道所有的单词都被匹配到鄙视自己没想清楚写了半天 最后发现题目意思都错了改了很多 最后代码和原来

2014-08-30 10:07:03 921

原创 POJ 1442 Black Box treap求区间第k大

题目来源:POJ 1442 Black Box题意:输入xi 输出前xi个数的第i大的数思路:试了下自己的treap模版#include #include #include #include using namespace std;struct Node{ Node *ch[2]; int r; int v; int s; Node(){} Node(int

2014-08-29 23:24:07 1213

原创 treap模版

#include #include #include using namespace std;struct Node{ Node *ch[2]; int r; int v; int s; Node(int v): v(v) { ch[0] = ch[1] = NULL; r = rand(); s = 1; } bool operator < (const Node&

2014-08-28 22:07:12 885

转载 Dancing Links题集

POJ3740     Easy Finding [精确覆盖基础题]HUST1017    Exact cover [精确覆盖基础]HDOJ3663Power Stations [精确覆盖]ZOJ3209   Treasure Map [精确覆盖]HDOJ2828Lamp [精确覆盖+重复覆盖判独]HDOJ3498whosyourdaddy [重复覆盖]HDOJ3529Bo

2014-08-27 22:25:46 890

转载 树形DP(个别未完成)

一、常规树形DP     1、 Hdu 1520 Anniversary party   每个节点有权值,子节点和父节点不能同时选,问最后能选的最大价值是多少?解题报告Here      2、Hdu 2196 Computer  经典题,求树每个点到其他点的最远距离,转化为有根树,深搜两次,一次记录到叶子的最远距离,一次更新最终答案。解题报告Here      3、Poj

2014-08-20 15:33:39 767

ACM 学习资料

ACM 学习资料 包括一些压缩包 和 数据结构的一点东西

2013-11-29

数据结构课件

数据结构的课件 感觉比书上的代码容易理解

2013-09-04

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除