![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构训练
00000koi
这个作者很懒,什么都没留下…
展开
-
并查集【原理及模板】
整理自紫书1.又来管理元素分组情况的数据结构2.可以合并、无法分割3.使用树形结构实现(不是二叉树)分组: 对应的树: ①初始化:n个节点表示n个元素,没有边②...原创 2018-12-14 21:39:10 · 167 阅读 · 0 评论 -
Q - POJ 1195 树状数组(二维树状数组,点修改,区间查询)
Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares form an S * S matrix with the rows and columns numbe...原创 2019-04-12 19:53:43 · 216 阅读 · 0 评论 -
C - POJ 2752 Hash
The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek th...原创 2019-04-03 20:55:47 · 171 阅读 · 0 评论 -
分块
长度为n的序列,把它分成根号n块,每一块的大小事根号n,每次更新的复杂度都是根号n。belong[maxn]//这个数在哪一块里面;block//表示每一块的大小;num//表示块数,即一共有多少块;l[maxn]//表示这个数所在块的左边界是什么;r[maxn]//表示这个数所在块的右边界是什么;void build(){ block = sqrt(n);//每块的大小...原创 2019-04-21 15:35:25 · 131 阅读 · 0 评论 -
RMQ算法
我们先用一个例题来描述一下,RMQ所解决的问题类型例:南将军统帅着N个士兵,士兵编号分别为1~N,南将军经常爱拿某一段编号内杀敌数最高的人与杀敌数最低的人进行比较,计算两个人的杀敌数差值,用这种方法一方面能鼓舞杀敌数高的人,另一方面也算是批评杀敌数低的人,起到了很好的效果。所以,南将军经常问军师小工第i号士兵到第J号士兵中,杀敌数最高的人与杀敌数最低的人之间的军工差值是多少。现在请你写一个...原创 2019-04-15 20:51:24 · 145 阅读 · 0 评论 -
I - POJ 3468 分块
You haveNintegers,A1,A2, ... ,AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the ...原创 2019-04-22 21:04:18 · 180 阅读 · 0 评论 -
K - POJ 3368 RMQ
You are given a sequence ofnintegersa1, a2, ... , anin non-decreasing order. In addition to that, you are given several queries consisting of indicesiandj(1 ≤ i ≤ j ≤ n). For each query, det...原创 2019-04-18 16:31:50 · 138 阅读 · 0 评论 -
M - POJ 2019 二维RMQ
FJ has decided to grow his own corn hybrid in order to help the cows make the best possible milk. To that end, he's looking to build the cornfield on the flattest piece of land he can find.FJ has, a...原创 2019-04-20 11:00:10 · 209 阅读 · 0 评论 -
二维RMQ
二维RMQ两种做法:1) O(n*m*log(m))-O(n)2) O(n*m*log(n)*log(m)-O(1)第一种方法:把每一行都当成一维RMQ处理代码:#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#incl...原创 2019-04-19 22:22:25 · 1245 阅读 · 1 评论 -
R - POJ 2299 树状数组求逆序对
In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted i...原创 2019-04-25 09:51:18 · 137 阅读 · 0 评论 -
J - POJ 2364 RMQ
For the daily milking, Farmer John'sNcows (1 ≤N≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things ...原创 2019-04-16 17:31:48 · 117 阅读 · 0 评论 -
B -POJ2406 Hash
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-...原创 2019-04-03 17:02:46 · 228 阅读 · 0 评论 -
并查集+贪心——基础并查集
A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the s...原创 2019-03-29 20:30:30 · 217 阅读 · 0 评论 -
并查集与带权并查集
一、并查集1、初始化//初始化n个元素void init(int n){ for(int i=0; i<n; i++) { par[i] = i; rank[i] = 0; }}2、查询到一个点的根int find(int x){ if(par[x] == x) return x;...原创 2019-03-31 21:03:10 · 120 阅读 · 0 评论 -
D - POJ 3349 Hash
You may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is really true. Your program will read information about a collection of snowflakes, and...原创 2019-04-15 20:58:17 · 118 阅读 · 0 评论 -
A - POJ 3461 Hash
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter'e'. He was a member of the Oulipo group. A quote from the book:Tout avait Pair normal, mais tout s...原创 2019-04-01 16:22:45 · 105 阅读 · 0 评论 -
字符串匹配的三个算法(KMP+字典树+AC自动机)
转载自:https://blog.csdn.net/qq_30346729/article/details/78835040?utm_source=blogxgwz8字符串匹配的意思是给一个字符串集合,和另一个字符串集合,看这两个集合交集是多少。若是都只有一个字符串,那么就看其中一个是否包含另外一个;若是父串集合(比较长的,被当做模板)的有多个,子串(拿去匹配的)只有一个,就是问这个子...转载 2019-03-31 22:33:59 · 187 阅读 · 0 评论 -
O - POJ 2352树状数组
Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and ...原创 2019-04-10 21:51:45 · 113 阅读 · 0 评论 -
P - POJ 2481 树状数组
Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line) in his field is particularly good.Farmer John has N co...原创 2019-04-11 21:08:07 · 72 阅读 · 0 评论 -
Hash(哈希)——解决字符串问题
关于字符串Hash:把字符串有效转化为一个整数把每个字符串有效地、唯一的映射到每个"不同"的整数,就可以很好地处理字符串;找到一个Hash函数,使得每一个字符串都能够映射到一个整数上;hash[i] = ( hash[i-1] * p + idx(s[i]) )%mod;字符串:abc, bbc, aba, aadaabac 字符串下标从0开始, 先把a映射为1, b映射为...原创 2019-04-02 16:06:36 · 1820 阅读 · 0 评论 -
树状数组【二维】
二维树状数组和一维树状数组的原理一样;首先,一维树状数组的储存结构为:C1 = A1C2 = A1 + A2C3 = A3C4 = A1 + A2 + A3 + A4C5 = A5C6 = A5 + A6C7 = A7C8 = A1 + A2 + A3 + A4 + A5 + A6 + A7 + A8……C16 = A1 + A2 + A3 + A4 + A5 + A...原创 2019-04-12 15:13:08 · 199 阅读 · 0 评论 -
N - HUD 3486 二分+RMQ
YaoYao has a company and he wants to employ m people recently. Since his company is so famous, there are n people coming for the interview. However, YaoYao is so busy that he has no time to interview ...原创 2019-04-20 17:02:35 · 152 阅读 · 0 评论