08 2018 档案
摘要:There is given the series of n closed intervals [ai; bi], where i=1,2,...,n. The sum of those intervals may be represented as a sum of closed pairwise
阅读全文
摘要:上图一共有5个区间,分别是[0,2]、[2,4]、[8,11]、[7,11]、[15,18]。如果要求这些区间合并后区间的大小,有两种简单的方法。 方法一:比较每两个区间的范围,如果两个区间有交集,则合并它们。最后所有区间会合并成几个离散的大区间,结果为这些区间大小之和。这种方法的时间复杂度是O(n
阅读全文
摘要:有两个区间A[a1,b1], B[a2,b2],判断这两个区间有没有交集。我们可以分为两种思维来判断: 给你两个区间[a, b]和[c, d],如果让你求出这两个区间的相交长度,你会怎么做呢? 不出意外的话,大多数同学就会进行分类讨论,看看那个区间在前,那个区间在后,分两种情况,然后对区间相交还是覆
阅读全文
摘要:1.最短路变形 【题意】给一个图,每条边有个距离和花费,要求创建一个子图,满足0点到其余点的距离总和最小,且边的总花费最小。 【注意】首先,数组要开<<1大; 其次,双关键字的最短路,即最小花费下最短路,要注意优先级就是贪心,可以在优先队列做文章,也可以直接在松弛判断当两条边相同,选择当前花费更加小
阅读全文
摘要:https://www.cnblogs.com/njczy2010/p/3930688.html https://blog.csdn.net/dominating413421391/article/details/44203019?locationNum=1&fps=1 https://blog.c
阅读全文
摘要:最后补充一下滚动数组降维: 其实就是状态转移后前面的数组的空间不用了 ,会造成浪费,而滚动数组就是利用这部分空间 写Dp经常需要大家开高维数组,比如F[t][i][j]。有的时候转移仅需要上一维数组,如F[t 1][i][j],而F[t 2],F[t 3]都不再有用,留着占用大量空间。我们可以用滚动
阅读全文
摘要:A 求和 时间限制: 1 Sec 空间限制: 256 MB 输入输出文件名:A.in,A.out 题目描述 给出一棵以1为根的有n个节点的树,树上每条边都有其边权。 求所有点对之间的路径上的边权和的总和。 输入格式: 第一行为n 接下来n 1行,每行三个整数,分别表示一条边的两端点编号和边权。(编号
阅读全文
摘要:这里贴一下勾股数的构造: 当a为大于1的奇数2n+1时,b=2n2+2n, c=2n2+2n+1。 实际上就是把a的平方数拆成两个连续自然数,例如: n=1时(a,b,c)=(3,4,5) n=2时(a,b,c)=(5,12,13) n=3时(a,b,c)=(7,24,25) 当a为大于2的偶数2n
阅读全文
摘要:"链接" 1.括号序列贪心/CF&51nod原题 【分析】: 贪心,每次到i的时候,假如你要在i里面要卖掉股票,获益是a[i], 肯定要在前面要么:1)把已经卖了的变成不买不卖,需要 a[j], 2)把已经不买不卖的变成买,需要 a[j] 【原题链接】: "CF&E" "CF&D" "51nod高卖
阅读全文
摘要:Given a integers x = 1, you have to apply Q (Q ≤ 100000) operations: Multiply, Divide. Input First line of the input file contains an integer T(0 incl
阅读全文
摘要:n个点(n include include include include include include include include include include include include include include include include include define m
阅读全文
摘要:给你一个长度为 $\left|s\right|$ 的01串 $s$ ,每次操作你可以任选一个 $k$ ,使01串的 $[1,k]$ 和 $(k,\left|s\right|]$ 分别翻转(其中一个区间可以为空),求经过任意次操作后能得到的最长的01交替出现的子串的长度。(实际题目中01用w和b代替)
阅读全文
摘要:"题目链接" 所有元素初始值为0才能这么做: ①l r全加1 a[l]++; a[r+1] ; 求一遍前缀和为元素本身。 求两遍前缀和为元素前缀和。 include include include include include include include include include inc
阅读全文
摘要:给你一个n个初始元素都为1的序列和m个询问q。 询问格式为:l r x(x为2or3) 最后求1~n所有数的GCD GCD:把每个数分别分解质因数,再把各数中的全部 公有质因数 提取出来连乘,所得的积就是这几个数的最大公约数。 include include include include incl
阅读全文
摘要:【前后缀枚举】
阅读全文
摘要:``` include include include include include include include include include include include include include include include include include include de
阅读全文
摘要:【例题】 1.POJ Drainage Ditches 【最大流EK算法模板】 include include include include include include include include include include include include include includ
阅读全文
摘要:https://www.luogu.org/problemnew/show/CF1027C include include include include include include include include include include include include include
阅读全文
摘要:Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to k
阅读全文
摘要:LCA,最近公共祖先,实现有多种不同的方法,在树上的问题中有着广泛的应用,比如说树上的最短路之类。 LCA的实现方法有很多,比如RMQ、树链剖分等。 今天来讲其中实现较为简单的三种算法: RMQ+时间戳、树上倍增(类似二分步长)、Tarjan算法(DFS+并查集)。
阅读全文
摘要:【模板】洛谷P3865 include include include include include include include include include include include include include include include include include in
阅读全文
摘要:定义 给定一个二分图G,在G的一个子图M中,M的边集{E}中的任意两条边都不依附于同一个顶点,则称M是一个匹配。 极大匹配(Maximal Matching)是指在当前已完成的匹配下,无法再通过增加未完成匹配的边的方式来增加匹配的边数。最大匹配(maximum matching)是所有极大匹配当中边
阅读全文
摘要:a[i]=a[i 1]+b[i 1]+1, b[i]=2 a[i 1] 5 ; a[1]=1,b[1]=1, 问a[x]=?,b[x]=? 很简单的递推,一步步推即可,但是,如果x是10^9,如何推? 思维:递推式可以化为矩阵乘积 那么,矩阵A[i]=A[i 1] B; A[i+1]=A[i] B=
阅读全文
摘要:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=2151 Input 第一行三个数n,m,v0 表示有n名萌新和m次调整,初始时全部萌新的集训难度都为v0 第2~m+1行 每行三个数或四个数 0 x y v 表示把 [x,y]区间内的萌新的集训难
阅读全文
摘要:有一个只含0和1的长度为n的串,问不含有101的所有串的个数。 ——不存在连续的101、010、111的字符串数量 HDU:https://cn.vjudge.net/problem/HDU-3485 51nod: https://blog.csdn.net/Viscu/article/detail
阅读全文
摘要:【例题】 一、单点更新 #include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include<iostream> #include<cstring> #include<set> #include<queue> #in
阅读全文
摘要:#include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include<iostream> #include<cstring> #include<set> #include<queue> #include<algori
阅读全文
摘要:【题意建模】: 你想娶酋长的女儿,但酋长要求你给一定数额金钱的聘礼。除了金钱外,酋长也允许你用部落里其他人的某物品加上一点钱作为聘礼。而其他人的物品也可以通过指定的另外一些人的某物品加上一些金钱获得。部落里的每个人有一个等级。你的整个交易过程涉及的人的等级只能在一个限定的差值内。问你最少需要多少金钱
阅读全文
摘要:【简述】: kmp算法:1 kmp是用来匹配字符串,只能够匹配单一的字符串2 kmp的算法的过程: 1:假设文本串的长度为n,模式串的长度为m; 2:先例用O(m)的时间去预处理next数组,next数组的意思指的是当前的字符串匹配失败后要转到的下一个状态; 3:利用o(n)的时间去完成匹配; 3
阅读全文
摘要:#include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include<iostream> #include<cstring> #include<set> #include<queue> #include<algori
阅读全文
摘要:1】学习了字典树之后,觉得它很明显的就是用空间来换时间,空间复杂度特别大,比如字典数单单存26个小写字母,那么每个节点的孩子节点都有26个孩子节点,字典树中的每一层都保留着不同单词的相同字母。 2】01字典树主要用于解决求异或最值的问题 #include<cstdio> #include<strin
阅读全文
摘要:RK法:https://www.cnblogs.com/16crow/p/6879988.html #include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include<iostream> #include<cstr
阅读全文
摘要:算法分析:预处理时间Θ(m),即求h,p,t的时间为,匹配时间在最坏情况下为Θ((n-m-1)m),因为可能出现每次都是可能命中点的情况。如T=a^n,P=a^m,此种情况下验证时间为Θ((n-m-1)m)。当然实际中,可能的命中点一般很少。假设有c个,则算法的期望匹配时间为O(n-m+1 +cm)
阅读全文
摘要:问题描述: Rabin-Karp的预处理时间是O(m),匹配时间O( ( n - m + 1 ) m )既然与朴素算法的匹配时间一样,而且还多了一些预处理时间,那为什么我们还要学习这个算法呢?虽然Rain-Karp在最坏的情况下与朴素匹配一样,但是实际应用中往往比朴素算法快很多。而且该算法的期望匹配
阅读全文
摘要:农夫约翰在探索他的许多农场,发现了一些惊人的虫洞。虫洞是很奇特的,因为它是一个单向通道,可让你进入虫洞的前达到目的地!他的N(1≤N≤500)个农场被编号为1..N,之间有M(1≤M≤2500)条路径,W(1≤W≤200)个虫洞。FJ作为一个狂热的时间旅行的爱好者,他要做到以下几点:开始在一个区域,
阅读全文
摘要:Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchang
阅读全文
摘要:1.正环 用 SPFA不断的进行松弛操作,发现当前金额可以比本身大就更新,同时记录更新次数。如果更新次数超过n次,说明存在”正“环。 2.负环 这里先说明下负环。(求最短距离的时候) 在我们用SPFA求最短路径的时候,如果存在负环,在松弛操作的时候总会加入队列 因为最小距离会越来越小,同样这里如果经
阅读全文
摘要:Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whe
阅读全文
摘要:Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but
阅读全文
摘要:1.到底如何求k短路的? 我们考虑,要求k短路,要先求出最短路/次短路/第三短路……/第(k-1)短路,然后访问到第k短路。 接下来的方法就是如此操作的。 2.f(x)的意义? 我们得到的f(x)更小,优先访问这个f(x)的点。 我们可以定义一组数{p,g,h},p是某一个点,g是估价,h是实际,那
阅读全文
摘要:Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the number of nuclear weapons have soared across the glo
阅读全文
摘要:#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug() puts("++++") #def...
阅读全文
摘要:动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这N个动物所构成的食物链关系进行描述: 第一种说法是"1 X Y",表示X和Y是同类。 第二种说
阅读全文
摘要:Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that
阅读全文
摘要:[树形DP](https://cn.vjudge.net/contest/123963#overview) #include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include<iostream> #include<
阅读全文
摘要:You, the leader of Starship Troopers, are sent to destroy a base of the bugs. The base is built underground. It is actually a huge cavern, which consi
阅读全文
摘要:ACboy很喜欢玩一种战略游戏,在一个地图上,有N座城堡,每座城堡都有一定的宝物,在每次游戏中ACboy允许攻克M个城堡并获得里面的宝物。但由于地理位置原因,有些城堡不能直接攻克,要攻克这些城堡必须先攻克其他某一个特定的城堡。你能帮ACboy算出要获得尽量多的宝物应该攻克哪M个城堡吗? Input每
阅读全文
摘要:不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 56193 Accepted Submission(s): 21755 Problem
阅读全文
摘要:1026: [SCOI2009]windy数 Description windy定义了一种windy数。不含前导零且相邻两个数字之差至少为2的正整数被称为windy数。 windy想知道,在A和B之间,包括A和B,总共有多少个windy数? windy定义了一种windy数。不含前导零且相邻两个数字
阅读全文
摘要:#include #include #include #include using namespace std; int t; long long dp[19][19][2005]; long long l, r; int digit[20]; long long dfs(int len,...int if4..., bool limit) { if (len == 0) ...
阅读全文
摘要:You are a member of the space station engineering team, and are assigned a task in the construction process of the station. You are expected to write
阅读全文
摘要:Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs you
阅读全文
摘要:The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22668 Accepted: 8038 Description Given a connected undirected graph, tell if
阅读全文
摘要:1001:枚举保留题目的集合,然后模拟(二进制状态压缩 暴力所选的问题k 0~1<<m-1。再把n个人的状态进行按位&) 1002:直接在输入的时候扫一遍就行了,顺便用前缀和统计出每个字母的出现次数 (也可以线段树、ST表) 1006:两次克鲁斯卡尔(并查集)
阅读全文
摘要:1:给出一个括号字符串,问这个字符串中符合规则的最长子串的长度。 【逆序枚举区间长度】 #include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include<iostream> #include<cstring> #
阅读全文
摘要:题目描述 某大学有N个职员,编号为1~N。他们之间有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司。现在有个周年庆宴会,宴会每邀请来一个职员都会增加一定的快乐指数Ri,但是呢,如果某个职员的上司来参加舞会了,那么这个职员就无论如何也不肯来参加舞会了。所以,请你编程计算
阅读全文
摘要:"比赛链接" A CSU 1588 现在有n堆果子,第i堆有ai个果子。现在要把这些果子合并成一堆,每次合并的代价是两堆果子的总果子数。求合并所有果子的最小代价。 Input 第一行包含一个整数T(T,greater q 1.把果子都push进q内; 2.当q的size大于1,不断取最小的两个top
阅读全文