自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Coldfresh的博客

keeeeeep!~

  • 博客(407)
  • 收藏
  • 关注

原创 【bzoj1284】树的计树(组合数学+prufer数列)

一个有n个结点的树,设它的结点分别为v1, v2, …, vn,已知第i个结点vi的度数为di,问满足这样的条件的不同的树有多少棵。给定n,d1, d2, …, dn,编程需要输出满足d(vi)=di的树的个数。Input 第一行是一个正整数n,表示树有n个结点。第二行有n个数,第i个数表示di,即树的第i个结点的度数。其中1<=n<=150,输入数据保证满足条件的树不超过10^...

2018-08-23 16:15:44 713

原创 【HRBUST - 1284 】编辑距离(简单dp)

俄罗斯科学家Vladimir Levenshtein在1965年提出了编辑距离概念。编辑距离,又称Levenshtein距离,是指两个字符串之间,由一个转成另一个所需的最少编辑操作次数。许可的三种编辑操作包括插入一个字符、删除一个字符、将一个字符替换成另一个字符。 至今,编辑距离一直在相似句子检索的领域中发挥着不可忽视的作用。我们不妨来设计一个程序,计算两个字符串的编辑距离。Input...

2018-08-23 15:18:27 315

原创 二项式反演

我们给定两个函数F(x)F(x)F(x)和f(x)f(x)f(x),定义域在非负整数上。 若存在如下给定关系: F(n)=∑i=0n(−1)iCinf(i)F(n)=∑i=0n(−1)iCnif(i)F(n)=\sum_{i=0}^n(-1)^iC_n^if(i) 则有:f(n)=∑i=0n(−1)iCinF(i)f(n)=∑i=0n(−1)iCniF(i)f(n)=\sum_{i=0}^n...

2018-08-22 21:49:44 1289

原创 【CodeForces - 622F 】The Sum of the k-th Powers (拉格朗日插值)

Examples Input 4 1 Output 10 Input 4 2 Output 30 Input 4 3 Output 100 Input 4 0 Output 4 这个就直接上我的模板就可以了.#include<iostream>#include<cstdio>#include<cmath>#defi...

2018-08-21 15:32:01 385

原创 求解n次函数多项式之拉格朗日插值

设F(x)=a0+a1x+a2x2+...+anxnF(x)=a0+a1x+a2x2+...+anxnF(x)=a_0+a_1x+a_2x^2+...+a_nx^n在一些题目中例如找规律,比如是我上次在区域赛的时候如果可以真名或者猜出一些式子是多项式,还有次数,那么我用的待定系数法,就可以解方程来做了。 可以直接手动解,但是也可以借助程序了。 这里就用到了一个东西叫拉格朗日插值法。 假如...

2018-08-21 10:44:15 7072

原创 【HDU-5000】Clone(dp)

Problem Description After eating food from Chernobyl, DRD got a super power: he could clone himself right now! He used this power for several times. He found out that this power was not as perfect as...

2018-08-16 20:29:09 201

原创 【HDU 5917】Instability(ramsey定理)

Long long ago, there was a prosperous kingdom which consisted of n cities and every two cites were connected by an undirected road.However, one day a big monster attacked the kingdom and some roads ...

2018-08-16 19:43:12 211

原创 【51nod】猪和回文

一只猪走进了一个森林。很凑巧的是,这个森林的形状是长方形的,有n行,m列组成。我们把这个长方形的行从上到下标记为1到n,列从左到右标记为1到m。处于第r行第c列的格子用(r,c)表示。刚开始的时候猪站在(1,1),他的目标是走到(n,m)。由于猪回家心切,他在(r,c)的时候,只会往(r+1,c)或(r,c+1)走。他不能走出这个森林。这只猪所在的森林是一个非同寻常的森林。有一些格子看起来...

2018-08-16 18:28:10 205

原创 【51nod】AVL树的种类

平衡二叉树(AVL树),是指左右子树高度差至多为1的二叉树,并且该树的左右两个子树也均为AVL树。 现在问题来了,给定AVL树的节点个数n,求有多少种形态的AVL树恰好有n个节点。 Input 一行,包含一个整数n。 (0 < n <= 2000) Output 一行表示结果,由于结果巨大,输出它对1000000007取余数的结果。 Input示例 10 Output示例...

2018-08-16 15:36:03 387

原创 【Timus 1132】 Square Root(二次同余)

上代码:#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#define ll long longusing namespace std;ll P(ll a,ll b,ll mod){ ll ans=1; w

2018-08-14 17:34:13 432

原创 计算模m的k次根

已知:k,b,mk,b,mk,b,m 求解同余式:xk≡b(mod m)xk≡b(mod m)x^k\equiv b(mod\ m)如果我们满足两个限制 1.gcd(b,m)=1gcd(b,m)=1gcd(b,m)=1 2.gcd(k,ϕ(m))=1gcd(k,ϕ(m))=1gcd(k,\phi(m))=1 那么我们是有快速的方法求解x的1.先计算ϕ(m)ϕ(m...

2018-08-14 10:48:43 415

原创 【2018 Multi-University Training Contest 7】Sequence(分块+矩阵快速幂)

Problem Description Let us define a sequence as below⎧⎩⎨⎪⎪⎪⎪⎪⎪F1F2Fn===ABC⋅Fn−2+D⋅Fn−1+⌊Pn⌋Your job is simple, for each task, you should output Fn module 109+7.Input The first line has only on...

2018-08-13 21:56:27 225

原创 【2018 Multi-University Training Contest 7】GuGuFishtion(莫比乌斯反演)

Problem Description题目链接 Today XianYu is too busy with his homework, but the boring GuGu is still disturbing him!!!!!! At the break time, an evil idea arises in XianYu’s mind. ‘Come on, you xxxxxxx ...

2018-08-13 18:05:47 397

原创 【2018 Multi-University Training Contest 6】bookshelf(莫比乌斯反演)

Problem Description Patrick Star bought a bookshelf, he named it ZYG !! Patrick Star has N book .The ZYG has K layers (count from 1 to K) and there is no limit on the capacity of each layer !No...

2018-08-12 20:31:45 210

原创 【wanaflyCamp】Steins;Gate(原根+FFT)

利用原根吧乘运算变成加运算,然后fft,但是不知道为什么就是过不去啊。。。 先把有问题的代码先贴一下,过会在调试一下: 代码:#include<iostream>#include<cstdio>#include<cmath>#define maxx 200005

2018-08-10 11:40:58 483 1

原创 【HDU - 4609 】3-idiots(FFT)

King OMeGa catched three men who had been streaking in the street. Looking as idiots though, the three men insisted that it was a kind of performance art, and begged the king to free them. Out of hatr...

2018-08-08 10:57:46 209

原创 【wanaflyCamp】平衡二叉树(dp)

题目描述平衡二叉树,顾名思义就是一棵“平衡”的二叉树。在这道题中,“平衡”的定义为,对于树中任意一个节点,都满足左右子树的高度差不超过 . 空树的高度定义为0,单个节点的高度为1,其他情况下树的高度定义为根节点左右子树高度最大值 + 1。 一棵在高度上平衡的树,节点数可能不平衡。再定义一棵树的不平衡度为这棵树中所有节点的左右子树的节点数之差的最大值。 给定平衡的定义参数, 你需要求出所有高...

2018-08-07 17:26:32 646

原创 【51nod 1135】原根

设m是正整数,a是整数,若a模m的阶等于φ(m),则称a为模m的一个原根。(其中φ(m)表示m的欧拉函数) 给出1个质数P,找出P最小的原根。 Input 输入1个质数P(3 <= P <= 10^9) Output 输出P最小的原根。 Input示例 3 Output示例 2问题解决的是如何求一个质数的原根。,原根的定义我在之前的一篇文章写过,这里来讲是如何实现...

2018-08-07 12:00:39 186

原创 【wanaflyCamp】Growth(dp)

题目描述弱弱有两个属性a和b,这两个属性初始的时候均为0,每一天他可以通过努力,让a涨1点或b涨1点。 为了激励弱弱努力学习,我们共有n种奖励,第i种奖励有xi,yi,zi三种属性,若a ≥ xi且b ≥ yi,则弱弱在接下来的每一天都可以得到zi的分数。 问m天以后弱弱最多能得到多少分数。 输入第一行一个两个整数n和m(1 ≤ n ≤ 1000,1 ≤ m ≤ 2000000...

2018-08-06 16:25:48 325

原创 【wanaflyCamp】电音之王

代码: 学会了新姿势,以前只会longnlongnlongn的快速乘,无限T…后来想起我原来很久以前其实是学过的。#include<iostream>#include<cstdio>#define ll long long#define LL long longusing namespace std;inline LL mul(LL x,LL y,L...

2018-08-06 10:20:32 565

原创 Ascending Rating【2018 Multi-University Training Contest 3 A题】(单调队列)

Problem Description Before the start of contest, there are n ICPC contestants waiting in a long queue. They are labeled by 1 to n from left to right. It can be easily found that the i-th contestant’s...

2018-07-30 20:52:45 225

原创 【51nod 1222】 最小公倍数计数

**题目来源: Project Euler 基准时间限制:6 秒 空间限制:131072 KB 分值: 640 难度:8级算法题** 定义F(n)表示最小公倍数为n的二元组的数量。 即:如果存在两个数(二元组)X,Y(X <= Y),它们的最小公倍数为N,则F(n)的计数加1。 例如:F(6) = 5,因为[2,3] [1,6] [2,6] [3,6] [6,6]的最小公倍数等于6...

2018-07-30 20:09:32 306

原创 【51nod 1227】 平均最小公倍数(杜教筛)

题目来源: Project Euler 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 640 难度:8级算法题 重点内容 Lcm(a,b)表示a和b的最小公倍数,A(n)表示Lcm(n,i)的平均数(1 <= i <= n), 例如:A(4) = (Lcm(1,4) + Lcm(2,4) + Lcm(3,4) + Lcm(4,4)) / 4 = (4 + 4 +...

2018-07-29 21:07:24 428

原创 【51nod1237】 最大公约数之和 V3 (杜教筛)

基准时间限制:5 秒 空间限制:262144 KB 分值: 640 难度:8级算法题 给出一个数N,输出小于等于N的所有数,两两之间的最大公约数之和。相当于计算这段程序(程序中的gcd(i,j)表示i与j的最大公约数): 由于结果很大,输出Mod 1000000007的结果。G=0; for(i=1;i<=N;i++) for(j=1;j<=N;j++) { ...

2018-07-29 20:03:14 442

原创 【51nod 1238】 最小公倍数之和 V3(杜教筛)

基准时间限制:8 秒 空间限制:262144 KB 分值: 640 难度:8级算法题 收藏 关注 出一个数N,输出小于等于N的所有数,两两之间的最小公倍数之和。相当于计算这段程序(程序中的lcm(i,j)表示i与j的最小公倍数): 由于结果很大,输出Mod 1000000007的结果。G=0; for(i=1;i<=N;i++) for(j=1;j&

2018-07-29 18:22:14 396

原创 Maximum Mode【Nowcoder多校训练第4场G题】(离散化+二分)

来源:牛客网题目描述 The mode of an integer sequence is the value that appears most often. Chiaki has n integersa1,a2,...,ana1,a2,...,an a_1,a_2,...,a_n. She woud like to delete exactly m of them such that:...

2018-07-28 16:59:06 218

原创 【HDU 5608】function(杜教筛)

Problem Description There is a function f(x),which is defined on the natural numbers set N,satisfies the following eqautionN2−3N+2=∑d|Nf(d)N2−3N+2=∑d|Nf(d)N^2−3N+2=\sum_{d|N}f(d)calulate ∑ni=1f(i...

2018-07-27 21:03:18 255

原创 【51nod 1239】 欧拉函数之和(杜教筛)

基准时间限制:3 秒 空间限制:131072 KB 分值: 320 难度:7级算法题 对正整数n,欧拉函数是小于或等于n的数中与n互质的数的数目。此函数以其首名研究者欧拉命名,它又称为Euler’s totient function、φ函数、欧拉商数等。例如:φ(8) = 4(Phi(8) = 4),因为1,3,5,7均和8互质。 S(n) = Phi(1) + Phi(2) + …… Ph...

2018-07-27 18:57:33 369

原创 【51nod 1244】 莫比乌斯函数之和 (杜教筛)

莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出。梅滕斯(Mertens)首先使用μ(n)(miu(n))作为莫比乌斯函数的记号。具体定义如下: 如果一个数包含平方因子,那么miu(n) = 0。例如:miu(4), miu(12), miu(18) = 0。 如果一个数不包含平方因子,并且有k个不同的质因子,那么miu(n) = (-1)^k。例如:miu(2), miu(3), miu(3...

2018-07-27 17:01:38 600

原创 若干式子的证明

一些定理: 1.设f,gf,gf,g为两个数论函数,ttt为完全积性函数,若:f(n)=∑i=1nt(i)g(⌊ni⌋)f(n)=∑i=1nt(i)g(⌊ni⌋)f(n)=\sum_{i=1}^nt(i)g(\lfloor \frac{n}{i}\rfloor) 则:g(n)=∑i=1nμ(i)t(i)f(⌊ni⌋)g(n)=∑i=1nμ(i)t(i)f(⌊ni⌋)g(n)=\sum_{i=1...

2018-07-27 16:10:05 448

原创 Naive Operations【2018 Multi-University Training Contest 2 G题】(线段树)

Problem Description In a galaxy far, far away, there are two integer sequence a and b of length n. b is a static permutation of 1 to n. Initially a is filled with zeroes. There are two kind of oper...

2018-07-26 17:21:25 178

原创 Distinct Values【2018 Multi-University Training Contest 1 D题】(构造)(贪心)

Problem Description Chiaki has an array of n positive integers. You are told some facts about the array: for every two elements ai and aj in the subarray a_l..r(l≤i<j≤r),ai≠ajr(l≤i<j≤r),ai≠ajr ...

2018-07-24 23:52:18 178

原创 关于一些函数求前缀和的问题

1.设f(n)f(n)f(n)为n的因子的和,求: ∑i=1nf(i)∑i=1nf(i)\sum_{i=1}^nf(i) 其中n<1012n<1012nans=∑in∑jn[j|i]∗j=∑jnj∑in[j|i]=∑j=1n⌊nj⌋ans=∑in∑jn[j|i]∗j=∑jnj∑in[j|i]=∑j=1n⌊nj⌋ans=\sum_i^n\sum_j^n[j|i]*j\\=\sum_j...

2018-07-24 20:38:55 411

原创 今天让我们来学一学积性函数的筛法

第一件事情我们要知道的是:积性函数都可以线性筛。(就是说复杂度是O(n)O(n)O(n) 积性函数的性质不说了,在说说常见的几个积性函数。 μ(n)μ(n)\mu(n):莫比乌斯函数 ϕ(n)ϕ(n)\phi(n):欧拉函数 d(n)d(n)d(n):一个数n的约数个数 σ(n)σ(n)σ(n):一个数n的约数和那我们就来筛筛看吧,(注意:所有线性筛积性函数都必须基于线性筛素数。 ...

2018-07-22 18:24:11 436

原创 素数的线性欧拉筛

先上代码:#define maxx 400005using namespace std;int prime[100005];bool p[maxx];int cnt=0;void init(){ for(int i=2;i<maxx;i++) { if(!p[i]) prime[cnt++]=i; ...

2018-07-22 15:10:39 303

原创 今天让我们来学一学杜教筛

终于想起来要学这个了,但是似乎还没学完? 先写一部分那就。注意:在此讨论的函数的定义域均在正整数上讨论 积性函数定义: 设有f(x)f(x)f(x)满足:若p和q为质数p和q为质数p和q为质数 则有f(p∗q)=f(q)∗f(p)f(p∗q)=f(q)∗f(p)f(p*q)=f(q)*f(p) 那么我们称f(x)f(x)f(x)为积性函数。 如: 1.常数函数 l(n)=1l(n...

2018-07-20 20:16:20 1288

原创 【HDU - 1402】A * B Problem Plus (FFT)

Calculate A * B. Input Each line will contain two integers A and B. Process to end of file. Note: the length of each integer will not exceed 50000. Output For each case, output A * B in one li...

2018-07-20 16:18:19 225

原创 Different Integers(Nowcoder多校训练第一场J题)(树状数组+离线)

Given a sequence of integers a 1 , a 2 , …, a n and q pairs of integers (l 1 , r 1 ), (l 2 , r 2 ), …, (l q , r q ), find count(l 1 , r 1 ), count(l 2 , r 2 ), …, count(l q , r q ) where count(i, j) ...

2018-07-19 20:33:54 462

原创 Data Structure? HDU - 4217(树状数组+二分)

Data structure is one of the basic skills for Computer Science students, which is a particular way of storing and organizing data in a computer so that it can be used efficiently. Today let me introdu...

2018-07-18 23:54:20 193

原创 Query on A Tree HDU - 6191 (离线+01字典树合并)

Monkey A lives on a tree, he always plays on this tree. One day, monkey A learned about one of the bit-operations, xor. He was keen of this interesting operation and wanted to practise it at once. ...

2018-07-17 18:41:37 213

空空如也

空空如也

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

TA关注的人

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